Bopytex/bopytex/worker/generate.py

22 lines
523 B
Python
Raw Normal View History

2022-04-10 13:50:58 +00:00
from jinja2.environment import Template
2022-04-13 10:26:04 +00:00
from bopytex.message import Message
2022-04-10 13:50:58 +00:00
def generate(args, deps, output):
env = args["jinja2"]["environment"]
template = env.get_template(deps[0])
2022-04-13 10:26:04 +00:00
try:
with open(output, "w") as out:
out.write(tpl2tex(template, metas=args))
return Message(0, [f"GENERATE - {deps[0]} to {output}"], [])
except Exception as e:
return Message(0, [], [e])
2022-04-10 13:50:58 +00:00
def tpl2tex(template: Template, metas: dict = {}) -> str:
return template.render(metas)