| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- #!/usr/bin/env python
- import json
- import os
- from jinja2 import Environment, FileSystemLoader
- # Load configuration from config.json
- with open('config.json', 'r') as config_file:
- config = json.load(config_file)
- dictfile = {}
- # Read variables from the TEMPLATE_VARS dictionary
- dictfile = config["TEMPLATE_VARS"]
- def do_template(dict, out, templ, run_script=False, run_dir=None, shell=None):
- env = Environment(loader=FileSystemLoader('./'))
- template = env.get_template(templ)
- rendered_content = template.render(dict)
- print("Dictionary applied", json.dumps(dict, indent=4), "To, ", out)
- with open(out, 'w') as outfile:
- outfile.write(rendered_content)
- print("Runscript:", str(run_script))
- if run_script:
- os.chmod(out, 0o755)
- if run_dir != "none" and shell != "none":
- os.system(f"cd {run_dir} && {shell} {out}")
- else:
- os.system(out)
- # Run jinja2 templates
- templates = config["JINJA_TEMP"]
- for item in templates:
- out_tpl = item["OUT_FILE"]
- in_tpl = item["IN_FILE"]
- run_script = item.get("RUN_SCRIPT", False)
- run_dir = item.get("RUN_DIR")
- shell = item.get("SHELL")
- do_template(dictfile, out_tpl, in_tpl, run_script=run_script, run_dir=run_dir, shell=shell)
|