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

style fixes configd

parent cba10171
......@@ -29,3 +29,4 @@
--------------------------------------------------------------------------------------
package : configd
"""
......@@ -30,8 +30,9 @@
package : configd
"""
class Helpers(object):
def __init__(self,template_in_data):
def __init__(self, template_in_data):
""" initialize template helpers
:param template_in_data:
......@@ -39,22 +40,22 @@ class Helpers(object):
"""
self._template_in_data = template_in_data
def getNodeByTag(self,tag):
def getNodeByTag(self, tag):
""" get tree node by tag
:param tag: tag in dot notation (section.item)
:return: dict or None if not found
"""
node = self._template_in_data
for item in tag.split('.'):
if node.has_key(item):
node=node[item]
if item in node:
node = node[item]
else:
# not found
return None
# path found, return
return node
def exists(self,tag):
def exists(self, tag):
"""
check if node exists in dictionary structure
:param tag: tag in dot notation (section.item)
......@@ -64,3 +65,4 @@ class Helpers(object):
return True
else:
return False
......@@ -43,7 +43,7 @@ import xml.etree.cElementTree as ElementTree
class Config(object):
def __init__(self,filename):
def __init__(self, filename):
self._filename = filename
self._config_data = {}
self._file_mod = 0
......@@ -62,25 +62,25 @@ class Config(object):
self._config_data = self._traverse(root)
self._file_mod = mod_time
def _traverse(self,xmlNode):
def _traverse(self, xmlNode):
""" traverse xml node and return ordered dictionary structure
:param xmlNode: ElementTree node
:return: collections.OrderedDict
"""
this_item = collections.OrderedDict()
if len(list(xmlNode)) > 0 :
if len(list(xmlNode)) > 0:
for item in list(xmlNode):
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:
tmp_item = copy.deepcopy(this_item[item.tag])
this_item[item.tag] = []
this_item[item.tag].append(tmp_item)
if item_content != None:
if item_content is not None:
# skip empty fields
this_item[item.tag].append(item_content)
elif item_content != None:
elif item_content is not None:
# create a new named item
this_item[item.tag] = self._traverse(item)
else:
......@@ -89,8 +89,7 @@ class Config(object):
return this_item
def indent(self,elem, level=0):
def indent(self, elem, level=0):
""" indent cElementTree (prettyprint fix)
used from : http://infix.se/2007/02/06/gentlemen-indent-your-xml
@param elem: cElementTree
......@@ -110,7 +109,6 @@ class Config(object):
if level and (not elem.tail or not elem.tail.strip()):
elem.tail = i
def get(self):
""" get active config data, load from disc if file in memory is different
......
......@@ -37,7 +37,7 @@ __author__ = 'Ad Schellevis'
import syslog
def execute(action,parameters):
def execute(action, parameters):
""" wrapper for inline functions
:param action: action object ( processhandler.Action type )
......@@ -54,7 +54,7 @@ def execute(action,parameters):
# send generated filenames to syslog
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 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