Compare commits

..

1 Commits

Author SHA1 Message Date
e10915689a Render all template using python and jinja 2025-11-08 06:14:45 +01:00
2 changed files with 7 additions and 17 deletions

View File

@@ -1,4 +1,3 @@
PyYAML==6.0.3 PyYAML==6.0.3
requests==2.32.5 requests==2.32.5
Jinja2==3.1.6 Jinja2==3.1.6
GitPython==3.1.45

View File

@@ -4,27 +4,18 @@
import functools import functools
import json import json
import os
import pathlib import pathlib
import git
import requests import requests
import yaml import yaml
from jinja2 import Environment, FileSystemLoader, StrictUndefined, Template from jinja2 import Environment, FileSystemLoader, StrictUndefined, Template
REPO = git.Repo(".", search_parent_directories=True) NODES = pathlib.Path("nodes")
assert REPO.working_dir is not None SCHEMATICS = pathlib.Path("schematics")
RENDERED = pathlib.Path("rendered")
ROOT = pathlib.Path(REPO.working_dir) PATCHES = Environment(loader=FileSystemLoader("patches"), undefined=StrictUndefined)
TEMPLATES = Environment(loader=FileSystemLoader("templates"), undefined=StrictUndefined)
NODES = ROOT.joinpath("nodes")
SCHEMATICS = ROOT.joinpath("schematics")
RENDERED = ROOT.joinpath("rendered")
PATCHES = Environment(
loader=FileSystemLoader(ROOT.joinpath("patches")), undefined=StrictUndefined
)
TEMPLATES = Environment(
loader=FileSystemLoader(ROOT.joinpath("templates")), undefined=StrictUndefined
)
def node_encoder(node: dict): def node_encoder(node: dict):
@@ -122,7 +113,7 @@ def main():
# Quick and dirty way to resolve all the templates using a custom encoder # 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)))) final_nodes.append(json.loads(json.dumps(node, cls=node_encoder(node))))
with open(ROOT.joinpath("config.yaml")) as fyaml: with open("config.yaml") as fyaml:
config = yaml.safe_load(fyaml) config = yaml.safe_load(fyaml)
RENDERED.mkdir(exist_ok=True) RENDERED.mkdir(exist_ok=True)