Feat: arrange variables for templates
Split in 3 categories - from "options" key build with default_config, file_config and cli options - from "subject" key build csv or quantity of subject - other in direct access from "direct_access" dictionnary inside the file_config
This commit is contained in:
@@ -4,12 +4,26 @@ from bopytex.message import Message
|
||||
|
||||
|
||||
def generate(args, deps, output):
|
||||
env = args["jinja2"]["environment"]
|
||||
env = args["options"]["jinja2"]["environment"]
|
||||
template = env.get_template(deps[0])
|
||||
|
||||
variables = {
|
||||
"options":args["options"],
|
||||
"subject":args["subject"],
|
||||
}
|
||||
|
||||
try:
|
||||
args["options"]["direct_access"]
|
||||
except KeyError:
|
||||
pass
|
||||
else:
|
||||
for (k,v) in args["options"]["direct_access"].items():
|
||||
if k not in ["options", "subject"]:
|
||||
variables[k] = v
|
||||
|
||||
try:
|
||||
with open(output, "w") as out:
|
||||
fed = template.render(args)
|
||||
fed = template.render(variables)
|
||||
out.write(fed)
|
||||
|
||||
return Message(0, [f"GENERATE - {deps[0]} to {output}"], [])
|
||||
|
||||
Reference in New Issue
Block a user