Render all template using python and jinja
This commit is contained in:
13
tools/merge
Executable file → Normal file
13
tools/merge
Executable file → Normal 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__":
|
||||
|
||||
Reference in New Issue
Block a user