Render all template using python and jinja

This commit is contained in:
2025-11-08 06:14:30 +01:00
parent 3290a76193
commit e10915689a
4 changed files with 158 additions and 34 deletions

13
tools/merge Executable file → Normal file
View File

@@ -12,6 +12,7 @@ from jinja2 import Environment, FileSystemLoader, StrictUndefined, Template
NODES = pathlib.Path("nodes")
SCHEMATICS = pathlib.Path("schematics")
RENDERED = pathlib.Path("rendered")
PATCHES = Environment(loader=FileSystemLoader("patches"), undefined=StrictUndefined)
TEMPLATES = Environment(loader=FileSystemLoader("templates"), undefined=StrictUndefined)
@@ -111,8 +112,16 @@ def main():
# Quick and dirty way to resolve all the templates using a custom encoder
final_nodes.append(json.loads(json.dumps(node, cls=node_encoder(node))))
# Dump everything to json
print(json.dumps(final_nodes, indent=4))
with open("config.yaml") as fyaml:
config = yaml.safe_load(fyaml)
RENDERED.mkdir(exist_ok=True)
for template_name in TEMPLATES.list_templates():
template = TEMPLATES.get_template(template_name)
rendered = template.render(nodes=final_nodes, config=config)
with open(RENDERED.joinpath(template_name), "w") as f:
f.write(rendered)
if __name__ == "__main__":