summaryrefslogtreecommitdiffstats
path: root/src/lib/Server/Plugins/SGenshi.py
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2007-07-19 19:20:51 +0000
committerNarayan Desai <desai@mcs.anl.gov>2007-07-19 19:20:51 +0000
commit502c32d1fbd69aec17d3809348dd05188fba5108 (patch)
tree774269b6b0a6528beba1398f67fa07e7e6aaf3c4 /src/lib/Server/Plugins/SGenshi.py
parent59635c22773a8a7b26c7c27891e999a3f71bbd1a (diff)
downloadbcfg2-502c32d1fbd69aec17d3809348dd05188fba5108.tar.gz
bcfg2-502c32d1fbd69aec17d3809348dd05188fba5108.tar.bz2
bcfg2-502c32d1fbd69aec17d3809348dd05188fba5108.zip
Add SGenshi plugin
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@3506 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Server/Plugins/SGenshi.py')
-rw-r--r--src/lib/Server/Plugins/SGenshi.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/lib/Server/Plugins/SGenshi.py b/src/lib/Server/Plugins/SGenshi.py
new file mode 100644
index 000000000..9c196190d
--- /dev/null
+++ b/src/lib/Server/Plugins/SGenshi.py
@@ -0,0 +1,36 @@
+'''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')
+
+class TemplateFile(Bcfg2.Server.Plugin.FileBacked):
+ 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)
+
+ def GetValue(self, metadata):
+ stream = self.template.generate(metadata=metadata)
+ data = stream.render('xml')
+ return lxml.etree.XML(data)
+
+class SGenshi(Bcfg2.Server.Plugin.Plugin,
+ Bcfg2.Server.Plugin.XMLDirectoryBacked):
+ __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)
+
+ def BuildStructures(self, metadata):
+ return [entry.GetValue(metadata) for entry in self.entries]
+