def __jinja_render_to_file(cls, template_path, template_file, module_name,
temp_dir, module_path, **context):
"""
Create the module from a jinja template.
:param template_file: name of the template file
:param module_name: the destination file name
:param temp_dir: a temporary working dir for jinja
:param context: dict of substitution variables
:return: None
"""
j2_tmpl_path = template_path
j2_env = Environment(loader=FileSystemLoader(j2_tmpl_path), keep_trailing_newline=True)
j2_tmpl = j2_env.get_template(template_file)
rendered = j2_tmpl.render(dict(temp_dir=temp_dir, **context))
with open(os.path.normpath(os.path.join(module_path, module_name)), 'wb') as f:
f.write(rendered.encode('utf8'))
评论列表
文章目录