summaryrefslogtreecommitdiff
path: root/contrib/render.py
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-10-19 18:20:26 +0200
committerChristian Grothoff <christian@grothoff.org>2017-10-26 22:39:59 +0200
commita946dc30bb53fa09e0a42cadd1e483b69ef2e349 (patch)
treed75d7e39a58906f0e4b0c9d7179328a2200fe047 /contrib/render.py
parentd107baa2c30980b85f6330f3f7c3287b4d58708b (diff)
downloadexchange-a946dc30bb53fa09e0a42cadd1e483b69ef2e349.tar.gz
exchange-a946dc30bb53fa09e0a42cadd1e483b69ef2e349.tar.bz2
exchange-a946dc30bb53fa09e0a42cadd1e483b69ef2e349.zip
start template for generating nicely formatted auditor reports
Diffstat (limited to 'contrib/render.py')
-rwxr-xr-xcontrib/render.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/contrib/render.py b/contrib/render.py
new file mode 100755
index 000000000..d31c7f9bd
--- /dev/null
+++ b/contrib/render.py
@@ -0,0 +1,38 @@
+#!/usr/bin/python
+# This file is in the public domain.
+
+"""
+Expand Jinja2 templates based on JSON input.
+
+First command-line argument must be the JSON input.
+The tool reads the template from stdin and writes
+the expanded output to stdout.
+
+@author Christian Grothoff
+"""
+
+import sys
+import json
+import jinja2
+from jinja2 import BaseLoader
+
+
+class StdinLoader(BaseLoader):
+ def __init__ (self):
+ self.path = '-'
+ def get_source(self, environment, template):
+ source = sys.stdin.read().decode('utf-8')
+ return source, self.path, lambda: false
+
+
+jsonFile = open (sys.argv[1], 'r')
+jsonData = json.load(jsonFile)
+
+jinjaEnv = jinja2.Environment(loader=StdinLoader(),
+ lstrip_blocks=True,
+ trim_blocks=True,
+ undefined=jinja2.StrictUndefined,
+ autoescape=False)
+tmpl = jinjaEnv.get_template('stdin');
+
+print(tmpl.render(data = jsonData))