Commit 8e107684 authored by Ad Schellevis's avatar Ad Schellevis

style fixes configd

parent cba10171
...@@ -29,3 +29,4 @@ ...@@ -29,3 +29,4 @@
-------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------
package : configd package : configd
""" """
...@@ -30,8 +30,9 @@ ...@@ -30,8 +30,9 @@
package : configd package : configd
""" """
class Helpers(object): class Helpers(object):
def __init__(self,template_in_data): def __init__(self, template_in_data):
""" initialize template helpers """ initialize template helpers
:param template_in_data: :param template_in_data:
...@@ -39,22 +40,22 @@ class Helpers(object): ...@@ -39,22 +40,22 @@ class Helpers(object):
""" """
self._template_in_data = template_in_data self._template_in_data = template_in_data
def getNodeByTag(self,tag): def getNodeByTag(self, tag):
""" get tree node by tag """ get tree node by tag
:param tag: tag in dot notation (section.item) :param tag: tag in dot notation (section.item)
:return: dict or None if not found :return: dict or None if not found
""" """
node = self._template_in_data node = self._template_in_data
for item in tag.split('.'): for item in tag.split('.'):
if node.has_key(item): if item in node:
node=node[item] node = node[item]
else: else:
# not found # not found
return None return None
# path found, return # path found, return
return node return node
def exists(self,tag): def exists(self, tag):
""" """
check if node exists in dictionary structure check if node exists in dictionary structure
:param tag: tag in dot notation (section.item) :param tag: tag in dot notation (section.item)
...@@ -64,3 +65,4 @@ class Helpers(object): ...@@ -64,3 +65,4 @@ class Helpers(object):
return True return True
else: else:
return False return False
...@@ -43,7 +43,7 @@ import xml.etree.cElementTree as ElementTree ...@@ -43,7 +43,7 @@ import xml.etree.cElementTree as ElementTree
class Config(object): class Config(object):
def __init__(self,filename): def __init__(self, filename):
self._filename = filename self._filename = filename
self._config_data = {} self._config_data = {}
self._file_mod = 0 self._file_mod = 0
...@@ -62,25 +62,25 @@ class Config(object): ...@@ -62,25 +62,25 @@ class Config(object):
self._config_data = self._traverse(root) self._config_data = self._traverse(root)
self._file_mod = mod_time self._file_mod = mod_time
def _traverse(self,xmlNode): def _traverse(self, xmlNode):
""" traverse xml node and return ordered dictionary structure """ traverse xml node and return ordered dictionary structure
:param xmlNode: ElementTree node :param xmlNode: ElementTree node
:return: collections.OrderedDict :return: collections.OrderedDict
""" """
this_item = collections.OrderedDict() this_item = collections.OrderedDict()
if len(list(xmlNode)) > 0 : if len(list(xmlNode)) > 0:
for item in list(xmlNode): for item in list(xmlNode):
item_content = self._traverse(item) item_content = self._traverse(item)
if this_item.has_key(item.tag): if item.tag in this_item:
if type(this_item[item.tag]) != list: if type(this_item[item.tag]) != list:
tmp_item = copy.deepcopy(this_item[item.tag]) tmp_item = copy.deepcopy(this_item[item.tag])
this_item[item.tag] = [] this_item[item.tag] = []
this_item[item.tag].append(tmp_item) this_item[item.tag].append(tmp_item)
if item_content != None: if item_content is not None:
# skip empty fields # skip empty fields
this_item[item.tag].append(item_content) this_item[item.tag].append(item_content)
elif item_content != None: elif item_content is not None:
# create a new named item # create a new named item
this_item[item.tag] = self._traverse(item) this_item[item.tag] = self._traverse(item)
else: else:
...@@ -89,8 +89,7 @@ class Config(object): ...@@ -89,8 +89,7 @@ class Config(object):
return this_item return this_item
def indent(self, elem, level=0):
def indent(self,elem, level=0):
""" indent cElementTree (prettyprint fix) """ indent cElementTree (prettyprint fix)
used from : http://infix.se/2007/02/06/gentlemen-indent-your-xml used from : http://infix.se/2007/02/06/gentlemen-indent-your-xml
@param elem: cElementTree @param elem: cElementTree
...@@ -110,7 +109,6 @@ class Config(object): ...@@ -110,7 +109,6 @@ class Config(object):
if level and (not elem.tail or not elem.tail.strip()): if level and (not elem.tail or not elem.tail.strip()):
elem.tail = i elem.tail = i
def get(self): def get(self):
""" get active config data, load from disc if file in memory is different """ get active config data, load from disc if file in memory is different
......
...@@ -37,14 +37,14 @@ __author__ = 'Ad Schellevis' ...@@ -37,14 +37,14 @@ __author__ = 'Ad Schellevis'
import syslog import syslog
def execute(action,parameters): def execute(action, parameters):
""" wrapper for inline functions """ wrapper for inline functions
:param action: action object ( processhandler.Action type ) :param action: action object ( processhandler.Action type )
:param parameters: parameter string :param parameters: parameter string
:return: status ( string ) :return: status ( string )
""" """
if action.command == 'template.reload': if action.command == 'template.reload':
import template import template
import config import config
tmpl = template.Template(action.root_dir) tmpl = template.Template(action.root_dir)
...@@ -54,7 +54,7 @@ def execute(action,parameters): ...@@ -54,7 +54,7 @@ def execute(action,parameters):
# send generated filenames to syslog # send generated filenames to syslog
for filename in filenames: for filename in filenames:
syslog.syslog(syslog.LOG_DEBUG,' %s generated %s' % ( parameters, filename ) ) syslog.syslog(syslog.LOG_DEBUG, ' %s generated %s' % (parameters, filename))
del conf del conf
del tmpl del tmpl
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment