Commit 51d347d4 authored by Chris Woodall's avatar Chris Woodall
Browse files

Added jinja2 templates to defaults with jinja2defaults

parent d70f20b4
Pipeline #3776 passed with stage
in 38 seconds
......@@ -75,6 +75,9 @@ mapping:
constdefault:
type: str
required: no
jinja2default:
type: str
required: no
export_for_mainboard:
type: bool
required: no
......
......@@ -20,6 +20,9 @@ import sys
import configparser
import click
def fmt_add(a, b, format="%i"):
return format % (int(str(a), 0) + int(str(b), 0))
def generate_eds_section(objdict):
eds_config = configparser.ConfigParser()
......@@ -111,6 +114,16 @@ def cli(ctx, doc_dir, output_dir, master_dir, yaml_files):
objdict['indexes'] = multikeysort(objdict['indexes'],
['index', 'subindex'])
env = jinja2.Environment(loader=jinja2.PackageLoader('objdict_generate', 'resources'))
env.globals['DataTypes'] = DataTypes
env.globals['node_id'] = objdict['node_id']
env.filters['fmt_add'] = fmt_add
# Go through and run templates on jinja2defaults fields
for index in objdict['indexes']:
if 'jinja2default' in index:
index["default"] = env.from_string(index["jinja2default"]).render()
company = {"name": "Barrett Technology, LLC",
"email": "support@barrett.com"}
......@@ -126,10 +139,9 @@ def cli(ctx, doc_dir, output_dir, master_dir, yaml_files):
eds_entries = generate_eds_section(objdict)
for output in outputs:
tmpl = jinja2.Template(get_resource_string(
output["template"]).decode("utf-8"))
tmpl.globals['DataTypes'] = DataTypes
tmpl = env.get_template(output["template"])
with open(output['name'], mode='w') as output_file:
output_file.write(tmpl.render(
date=arrow.now(), company=company, objdict=objdict, master=output.get("master")))
......
#!/usr/bin/env python3
__version__ = "0.4.0"
\ No newline at end of file
__version__ = "0.5.0"
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment