Commit 964d0f7c authored by Saurabh's avatar Saurabh

jinja2: fix display of source in traceback

parent e9b7c1b2
2.7 (2015-05-18)
================
* jinja2: fix display of source in traceback when there is an error in the
root template (or in instance parameters).
2.6 (2014-11-26)
================
......
from setuptools import setup, find_packages
import os
version = '2.6'
version = '2.7'
name = 'slapos.recipe.template'
long_description = open("README.txt").read() + "\n" + \
open(os.path.join('slapos', 'recipe',
......
......@@ -134,14 +134,13 @@ LOADER_TYPE_DICT = {
class Recipe(object):
mode = 0777 # BBB: 0666 may have been a better default value
loader = None
umask = None
def __init__(self, buildout, name, options):
template = options['template']
if template.startswith('inline:'):
template = template[7:].lstrip('\r\n')
self.get_template = lambda: template
source = template[7:].lstrip('\r\n')
template = '<inline>'
else:
template = zc.buildout.download.Download(
buildout['buildout'],
......@@ -150,7 +149,7 @@ class Recipe(object):
template,
md5sum=options.get('md5sum'),
)[0]
self.get_template = lambda: open(template).read()
source = open(template).read()
import_delimiter = options.get('import-delimiter',
DEFAULT_IMPORT_DELIMITER)
import_dict = {}
......@@ -167,10 +166,12 @@ class Recipe(object):
import_delimiter,
)
if import_dict:
self.loader = RelaxedPrefixLoader(import_dict,
loader = RelaxedPrefixLoader(import_dict,
delimiter=import_delimiter)
else:
loader = None
self.rendered = options['rendered']
self.extension_list = [x for x in (y.strip()
extension_list = [x for x in (y.strip()
for y in options.get('extensions', '').split()) if x]
self.context = context = DEFAULT_CONTEXT.copy()
if _buildout_safe_dumps is not None:
......@@ -191,6 +192,14 @@ class Recipe(object):
umask_value = options.get('umask')
if umask_value:
self.umask = int(umask_value, 8)
env = Environment(
extensions=extension_list,
undefined=StrictUndefined,
loader=loader)
# For overriding from_string method of jinja2
self.template = env.template_class.from_code(env,
env.compile(source, filename=template),
env.make_globals(None), None)
def install(self):
# Unlink any existing file, so umask is always applied.
......@@ -208,17 +217,7 @@ class Recipe(object):
with os.fdopen(os.open(self.rendered,
os.O_CREAT | os.O_EXCL | os.O_WRONLY,
self.mode), 'w') as out:
out.write(
Environment(
extensions=self.extension_list,
undefined=StrictUndefined,
loader=self.loader,
).from_string(
self.get_template(),
).render(
**self.context
)
)
out.write(self.template.render(**self.context))
return self.rendered
update = install
......
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