2021-08-27 18:24:14 +02:00
|
|
|
import json
|
|
|
|
|
2019-02-20 11:01:48 +01:00
|
|
|
from jinja2 import Environment, FileSystemLoader
|
2018-11-15 04:09:57 +01:00
|
|
|
from .misc import mark_file
|
|
|
|
|
2019-08-26 09:04:57 +02:00
|
|
|
jinja_env = Environment(loader=FileSystemLoader('/'), trim_blocks=True, lstrip_blocks=True)
|
2018-11-15 04:09:57 +01:00
|
|
|
|
2021-08-27 18:24:14 +02:00
|
|
|
def to_json(value):
|
|
|
|
return json.dumps(value)
|
|
|
|
|
|
|
|
jinja_env.filters['to_json'] = to_json
|
|
|
|
|
|
|
|
|
2018-11-15 04:09:57 +01:00
|
|
|
def render_jinja(src, dest,mode=0o640, uid=0, gid=0, **kw):
|
|
|
|
t = jinja_env.get_template(src)
|
|
|
|
with open(dest, 'w') as f:
|
|
|
|
f.write(t.render(**kw))
|
|
|
|
mark_file(dest, mode, uid, gid)
|
|
|
|
print("Generated configuration file: %s" % dest)
|