summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Server/Plugins/TemplateHelper.py
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2012-11-16 08:04:59 -0500
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2012-11-16 09:57:53 -0500
commit00627ba56075a0d0cb42356624ae6989521270bc (patch)
tree86567234d80ca6e30504a31ad4b63920a5a128dd /src/lib/Bcfg2/Server/Plugins/TemplateHelper.py
parent12684bada59c9ddc08165dad757682514b54634c (diff)
downloadbcfg2-00627ba56075a0d0cb42356624ae6989521270bc.tar.gz
bcfg2-00627ba56075a0d0cb42356624ae6989521270bc.tar.bz2
bcfg2-00627ba56075a0d0cb42356624ae6989521270bc.zip
cleaned up Templatehelper to help avoid some event handling errors
Diffstat (limited to 'src/lib/Bcfg2/Server/Plugins/TemplateHelper.py')
-rw-r--r--src/lib/Bcfg2/Server/Plugins/TemplateHelper.py46
1 files changed, 26 insertions, 20 deletions
diff --git a/src/lib/Bcfg2/Server/Plugins/TemplateHelper.py b/src/lib/Bcfg2/Server/Plugins/TemplateHelper.py
index 627c82f25..f09d4839e 100644
--- a/src/lib/Bcfg2/Server/Plugins/TemplateHelper.py
+++ b/src/lib/Bcfg2/Server/Plugins/TemplateHelper.py
@@ -13,15 +13,25 @@ LOGGER = logging.getLogger(__name__)
MODULE_RE = re.compile(r'(?P<filename>(?P<module>[^\/]+)\.py)$')
-class HelperModule(Bcfg2.Server.Plugin.FileBacked):
+class HelperModule(object):
""" Representation of a TemplateHelper module """
def __init__(self, name, fam=None):
- Bcfg2.Server.Plugin.FileBacked.__init__(self, name, fam=fam)
+ self.name = name
+ self.fam = fam
self._module_name = MODULE_RE.search(self.name).group('module')
self._attrs = []
- def Index(self):
+ def HandleEvent(self, event=None):
+ """ HandleEvent is called whenever the FAM registers an event.
+
+ :param event: The event object
+ :type event: Bcfg2.Server.FileMonitor.Event
+ :returns: None
+ """
+ if event and event.code2str() not in ['exists', 'changed', 'created']:
+ return
+
try:
module = imp.load_source(self._module_name, self.name)
except: # pylint: disable=W0702
@@ -54,27 +64,23 @@ class HelperModule(Bcfg2.Server.Plugin.FileBacked):
self._attrs = newattrs
-class HelperSet(Bcfg2.Server.Plugin.DirectoryBacked):
- """ A set of template helper modules """
- ignore = re.compile("^(\.#.*|.*~|\\..*\\.(sw[px])|.*\.py[co])$")
- patterns = MODULE_RE
- __child__ = HelperModule
-
-
class TemplateHelper(Bcfg2.Server.Plugin.Plugin,
- Bcfg2.Server.Plugin.Connector):
+ Bcfg2.Server.Plugin.Connector,
+ Bcfg2.Server.Plugin.DirectoryBacked):
""" A plugin to provide helper classes and functions to templates """
- name = 'TemplateHelper'
__author__ = 'chris.a.st.pierre@gmail.com'
+ ignore = re.compile("^(\.#.*|.*~|\\..*\\.(sw[px])|.*\.py[co])$")
+ patterns = MODULE_RE
+ __child__ = HelperModule
def __init__(self, core, datastore):
Bcfg2.Server.Plugin.Plugin.__init__(self, core, datastore)
Bcfg2.Server.Plugin.Connector.__init__(self)
- self.helpers = HelperSet(self.data, core.fam)
+ Bcfg2.Server.Plugin.DirectoryBacked.__init__(self, self.data, core.fam)
def get_additional_data(self, _):
return dict([(h._module_name, h) # pylint: disable=W0212
- for h in self.helpers.entries.values()])
+ for h in self.entries.values()])
class TemplateHelperLint(Bcfg2.Server.Lint.ServerlessPlugin):
@@ -130,9 +136,9 @@ class TemplateHelperLint(Bcfg2.Server.Lint.ServerlessPlugin):
@classmethod
def Errors(cls):
- return {"templatehelper-import-error":"error",
- "templatehelper-no-export":"error",
- "templatehelper-nonlist-export":"error",
- "templatehelper-nonexistent-export":"error",
- "templatehelper-reserved-export":"error",
- "templatehelper-underscore-export":"warning"}
+ return {"templatehelper-import-error": "error",
+ "templatehelper-no-export": "error",
+ "templatehelper-nonlist-export": "error",
+ "templatehelper-nonexistent-export": "error",
+ "templatehelper-reserved-export": "error",
+ "templatehelper-underscore-export": "warning"}