diff options
author | Joe Digilio <jdigilio@imca.aps.anl.gov> | 2011-09-26 13:26:02 -0500 |
---|---|---|
committer | Sol Jerome <sol.jerome@gmail.com> | 2011-10-12 10:39:10 -0500 |
commit | beed44ac11bbf70449c080262f98fb3ecb951c62 (patch) | |
tree | 471655db5dec83aa10fcfd886e9477d6e7673c66 /src/lib | |
parent | 86452547586c80eb8f6c433c9acc14f4de451e15 (diff) | |
download | bcfg2-beed44ac11bbf70449c080262f98fb3ecb951c62.tar.gz bcfg2-beed44ac11bbf70449c080262f98fb3ecb951c62.tar.bz2 bcfg2-beed44ac11bbf70449c080262f98fb3ecb951c62.zip |
Cfg: Add support for .cheetah files
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/Server/Plugins/Cfg.py | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/src/lib/Server/Plugins/Cfg.py b/src/lib/Server/Plugins/Cfg.py index beea2c747..f202628cd 100644 --- a/src/lib/Server/Plugins/Cfg.py +++ b/src/lib/Server/Plugins/Cfg.py @@ -23,6 +23,13 @@ try: except: have_genshi = False +try: + import Cheetah.Template + import Cheetah.Parser + have_cheetah = True +except: + have_cheetah = False + logger = logging.getLogger('Bcfg2.Plugins.Cfg') @@ -80,7 +87,7 @@ class CfgMatcher: def __init__(self, fname): name = re.escape(fname) - self.basefile_reg = re.compile('^(?P<basename>%s)(|\\.H_(?P<hostname>\S+?)|.G(?P<prio>\d+)_(?P<group>\S+?))(?P<genshi>\\.genshi)?$' % name) + self.basefile_reg = re.compile('^(?P<basename>%s)(|\\.H_(?P<hostname>\S+?)|.G(?P<prio>\d+)_(?P<group>\S+?))((?P<genshi>\\.genshi)|(?P<cheetah>\\.cheetah))?$' % name) self.delta_reg = re.compile('^(?P<basename>%s)(|\\.H_(?P<hostname>\S+)|\\.G(?P<prio>\d+)_(?P<group>\S+))\\.(?P<delta>(cat|diff))$' % name) self.cat_count = fname.count(".cat") self.diff_count = fname.count(".diff") @@ -157,6 +164,25 @@ class CfgEntrySet(Bcfg2.Server.Plugin.EntrySet): e = sys.exc_info()[1] logger.error("Cfg: genshi exception: %s" % e) raise Bcfg2.Server.Plugin.PluginExecutionError + elif basefile.name.endswith(".cheetah"): + if not have_cheetah: + logger.error("Cfg: Cheetah is not available") + raise Bcfg2.Server.Plugin.PluginExecutionError + try: + fname = entry.get('realname', entry.get('name')) + s = {'useStackFrames': False} + template = Cheetah.Template.Template(open(basefile.name).read(), + compilerSettings=s) + template.metadata = metadata + template.path = fname + template.source_path = basefile.name + data = template.respond() + if data == '': + entry.set('empty', 'true') + except Exception: + e = sys.exc_info()[1] + logger.error("Cfg: cheetah exception: %s" % e) + raise Bcfg2.Server.Plugin.PluginExecutionError else: data = basefile.data for delta in used: @@ -206,6 +232,9 @@ class CfgEntrySet(Bcfg2.Server.Plugin.EntrySet): if os.path.exists("%s.genshi" % name): logger.error("Cfg: Unable to pull data for genshi types") raise Bcfg2.Server.Plugin.PluginExecutionError + elif os.path.exists("%s.cheetah" % name): + logger.error("Cfg: Unable to pull data for cheetah types") + raise Bcfg2.Server.Plugin.PluginExecutionError try: etext = new_entry['text'].encode(self.encoding) except: |