def create_script(filename, templatename, mode=EXEC_MODE, **kwargs):
"""This Creates a file from a JINJA template.
The templates exist in our lib/python/treadmill/templates directory.
:param ``str`` filename:
Name of the file to generate.
:param ``str`` templatename:
The name of the template file.
:param ``int`` mode:
The mode for the file (Defaults to +x).
:param ``dict`` kwargs:
key/value passed into the template.
"""
filepath = os.path.dirname(filename)
with tempfile.NamedTemporaryFile(dir=filepath, delete=False) as f:
for data in generate_template(templatename, **kwargs):
f.write(data)
if os.name == 'posix':
# cast to int required in order for default EXEC_MODE to work
os.fchmod(f.fileno(), int(mode))
os.rename(f.name, filename)
评论列表
文章目录