diff options
author | Narayan Desai <desai@mcs.anl.gov> | 2007-07-19 19:20:51 +0000 |
---|---|---|
committer | Narayan Desai <desai@mcs.anl.gov> | 2007-07-19 19:20:51 +0000 |
commit | 502c32d1fbd69aec17d3809348dd05188fba5108 (patch) | |
tree | 774269b6b0a6528beba1398f67fa07e7e6aaf3c4 /src | |
parent | 59635c22773a8a7b26c7c27891e999a3f71bbd1a (diff) | |
download | bcfg2-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')
-rw-r--r-- | src/lib/Server/Plugins/SGenshi.py | 36 | ||||
-rw-r--r-- | src/lib/Server/Plugins/__init__.py | 2 |
2 files changed, 37 insertions, 1 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] + diff --git a/src/lib/Server/Plugins/__init__.py b/src/lib/Server/Plugins/__init__.py index 484162451..bd75f48ed 100644 --- a/src/lib/Server/Plugins/__init__.py +++ b/src/lib/Server/Plugins/__init__.py @@ -3,4 +3,4 @@ __revision__ = '$Revision$' all = ['Account', 'Base', 'Bundler', 'Cfg', 'Hostbase', 'Metadata', 'Pkgmgr', 'Rules', 'SSHbase', 'Svcmgr', 'TCheetah', - 'TGenshi', 'Vhost'] + 'SGenshi', 'TGenshi', 'Vhost'] |