Commit d1c33747 authored by André Anjos's avatar André Anjos 💬

Make jinja2 complain if a variable is not defined for generation

parent 60291e10
Pipeline #11295 passed with stages
in 6 minutes and 26 seconds
......@@ -159,9 +159,14 @@ def generate(variables, template):
str: A generated template you can save
Raises:
jinja2.UndefinedError: if a variable used in the template is undefined
'''
env = jinja2.Environment()
env = jinja2.Environment(undefined=jinja2.StrictUndefined)
for c in expand(variables):
yield env.from_string(template).render(c)
......@@ -185,8 +190,13 @@ def aggregate(variables, template):
str: A generated template you can save
Raises:
jinja2.UndefinedError: if a variable used in the template is undefined
'''
env = jinja2.Environment()
env = jinja2.Environment(undefined=jinja2.StrictUndefined)
d = {'cfgset': list(expand(variables))}
return jinja2.Environment().from_string(template).render(d)
return env.from_string(template).render(d)
......@@ -120,6 +120,7 @@ def main(command_line_options = None):
dirname = os.path.dirname(fname)
if dirname: tools.makedirs_safe(dirname)
with open(fname, 'wt') as f: f.write(data)
logger.info('Wrote `%s\'', fname)
# if user passed aggregator, do it as well
if args.aggtmpl and args.aggout:
......@@ -129,5 +130,6 @@ def main(command_line_options = None):
dirname = os.path.dirname(args.aggout)
if dirname: tools.makedirs_safe(dirname)
with open(args.aggout, 'wt') as f: f.write(data)
logger.info('Wrote `%s\'', args.aggout)
return 0
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment