2022-03-10 00:10:07 +03:00
|
|
|
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
|
|
|
|
)
|
|
|
|
|
2022-03-10 00:10:07 +03:00
|
|
|
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)
|
2022-03-10 00:10:07 +03:00
|
|
|
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
|
|
|
|
|
2022-03-10 00:10:07 +03:00
|
|
|
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 00:10:07 +03:00
|
|
|
|
|
|
|
|
2022-03-10 23:45:56 +03:00
|
|
|
template = env.get_template(relfilepath)
|
2022-03-10 00:10:07 +03:00
|
|
|
result = template.render(**data)
|
|
|
|
|
|
|
|
with open(trgfile,"w") as filed:
|
|
|
|
filed.write(result)
|