summaryrefslogtreecommitdiffstats
path: root/src/lib/Server
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/Server')
-rw-r--r--src/lib/Server/Plugins/SGenshi.py50
1 files changed, 41 insertions, 9 deletions
diff --git a/src/lib/Server/Plugins/SGenshi.py b/src/lib/Server/Plugins/SGenshi.py
index 11731ef78..76d1dd6bf 100644
--- a/src/lib/Server/Plugins/SGenshi.py
+++ b/src/lib/Server/Plugins/SGenshi.py
@@ -1,37 +1,69 @@
'''This module implements a templating generator based on Genshi'''
__revision__ = '$Revision$'
-import genshi.template
import Bcfg2.Server.Plugin
import lxml.etree, logging
logger = logging.getLogger('Bcfg2.Plugins.SGenshi')
+try:
+ import genshi.template, genshi.core, genshi.template.base
+except:
+ logger.error("Failed to load Genshi; disabling SGenshi")
+ raise
+
+def removecomment(stream):
+ """A genshi filter that removes comments from the stream."""
+ for kind, data, pos in stream:
+ if kind is genshi.core.COMMENT:
+ continue
+ yield kind, data, pos
+
class TemplateFile(Bcfg2.Server.Plugin.FileBacked):
+ '''Genshi template file object'''
loader = genshi.template.TemplateLoader(auto_reload=True,
max_cache_size=64)
def HandleEvent(self, _=None):
- self.template = self.loader.load(self.name,
- cls=genshi.template.MarkupTemplate)
+ '''Process FAM/GAMIN event'''
+ try:
+ self.template = self.loader.load(self.name,
+ cls=genshi.template.MarkupTemplate)
+ except genshi.template.base.TemplateSyntaxError, e:
+ logger.error("SGenshi: Parse failure due to %s" % (e))
def GetValue(self, metadata):
- stream = self.template.generate(metadata=metadata)
+ '''Build actual structure contents'''
+ if not hasattr(self, 'template'):
+ logger.error("Template data for %s could not be loaded" % self.name)
+ raise Bcfg2.Server.Plugin.PluginExecutionError
+ stream = self.template.generate(metadata=metadata).filter(removecomment)
data = stream.render('xml')
return lxml.etree.XML(data)
class SGenshi(Bcfg2.Server.Plugin.Plugin,
Bcfg2.Server.Plugin.XMLDirectoryBacked):
+ '''SGenshi is a structure plugin that provides direct plugin access to templated structures'''
__child__ = TemplateFile
__name__ = 'SGenshi'
__version__ = '$Id$'
def __init__(self, core, datastore):
Bcfg2.Server.Plugin.Plugin.__init__(self, core, datastore)
- Bcfg2.Server.Plugin.XMLDirectoryBacked.__init__(self,
- self.data,
- self.core.fam)
+ try:
+ Bcfg2.Server.Plugin.XMLDirectoryBacked.__init__(self,
+ self.data,
+ self.core.fam)
+ except:
+ logger.error("Failed to load SGenshi repository; disabling SGenshi")
+ raise Bcfg2.Server.Plugin.PluginInitError
def BuildStructures(self, metadata):
- return [entry.GetValue(metadata) \
- for entry in self.entries.values()]
+ '''Build SGenshi structures'''
+ ret = []
+ for entry in self.entries.values():
+ try:
+ ret.append(entry.GetValue(metadata))
+ except Bcfg2.Server.Plugin.PluginExecutionError:
+ logger.error("SGenshi: Failed to template file %s" % entry.name)
+ return ret