summaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/Server/Plugins/Cfg.py31
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: