1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00
maloja/dev/update_dist_files.py

34 lines
731 B
Python
Raw Normal View History

import toml
import os
import jinja2
2022-03-10 23:45:56 +03:00
env = jinja2.Environment(
loader=jinja2.FileSystemLoader('dev/templates'),
autoescape=jinja2.select_autoescape(['html', 'xml']),
keep_trailing_newline=True
)
with open("pyproject.toml") as filed:
data = toml.load(filed)
templatedir = "./dev/templates"
for root,dirs,files in os.walk(templatedir):
2022-03-10 23:45:56 +03:00
reldirpath = os.path.relpath(root,start=templatedir)
for f in files:
2022-03-10 23:45:56 +03:00
relfilepath = os.path.join(reldirpath,f)
2022-03-10 09:00:08 +03:00
if not f.endswith('.jinja'): continue
srcfile = os.path.join(root,f)
2022-03-10 23:45:56 +03:00
trgfile = os.path.join(reldirpath,f.replace(".jinja",""))
2022-03-10 23:45:56 +03:00
template = env.get_template(relfilepath)
result = template.render(**data)
with open(trgfile,"w") as filed:
filed.write(result)