From 7e055c6eaf4291539c77932b29b8db0cc42c5d8c Mon Sep 17 00:00:00 2001 From: jwansek Date: Thu, 20 Jan 2022 18:51:27 +0000 Subject: started work on templating --- jinja_helpers.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 jinja_helpers.py (limited to 'jinja_helpers.py') diff --git a/jinja_helpers.py b/jinja_helpers.py new file mode 100644 index 0000000..af91786 --- /dev/null +++ b/jinja_helpers.py @@ -0,0 +1,30 @@ +"""Functions in this module will be avaliable to call in jinja templates""" +import yaml + +def recurse_class_tree_text(tree, indent = 4): + return yaml.dump(tree, indent = indent).replace(": {}", "") + +def flatten_struct(struct): + out = {} + for s in struct: + key = list(s.keys())[0] + out[key] = s[key] + return out + +def _get_helpers(): + import reflect + import os + + r = reflect.Reflect(os.getcwd()) + r.import_module("jinja_helpers") + return {k: v[0] for k, v in r.get_functions("jinja_helpers").items()} + +if __name__ == "__main__": + import json + with open("100301654_report.json", "r") as f: + init_struct = json.load(f)["files"] + + print(flatten_struct(flatten_struct(init_struct)["example.py"]["functions"])) + + + \ No newline at end of file -- cgit v1.2.3