--- /dev/null
+from __future__ import annotations
+
+from .templates import LOADER_TEMPLATE, WORKER_TEMPLATE
+
+
+class KresConfig:
+ def render_lua_worker(self) -> str:
+ return WORKER_TEMPLATE.render(cfg=self)
+
+ def render_lua_loader(self) -> str:
+ return LOADER_TEMPLATE.render(cfg=self)
--- /dev/null
+from __future__ import annotations
+
+from pathlib import Path
+
+from jinja2 import Environment, FileSystemLoader, StrictUndefined, Template
+
+
+def _get_templates_path() -> Path:
+ templates_path = Path(__file__).resolve().parent
+ if not templates_path.exists():
+ raise FileNotFoundError(templates_path)
+ if not templates_path.is_dir():
+ raise NotADirectoryError(templates_path)
+ return templates_path
+
+
+_TEMPLATES_PATH: Path = _get_templates_path()
+
+
+def _load_template_from_str(template: str) -> Template:
+ loader = FileSystemLoader(_TEMPLATES_PATH)
+ env = Environment(trim_blocks=True, lstrip_blocks=True, loader=loader, undefined=StrictUndefined)
+ return env.from_string(template)
+
+
+def _import_template(template: str) -> Template:
+ template_file = _TEMPLATES_PATH / template
+ with template_file.open() as file:
+ template = file.read()
+ return _load_template_from_str(template)
+
+
+SUPERVISORD_TEMPLATE: Template = _import_template("supervisord.toml.j2")
+
+WORKER_TEMPLATE: Template = _import_template("worker.lua.j2")
+
+LOADER_TEMPLATE: Template = _import_template("loader.lua.j2")