-
Notifications
You must be signed in to change notification settings - Fork 2
/
templater.py
executable file
·42 lines (32 loc) · 1 KB
/
templater.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3
import logging
import os.path
import sys
import jinja2
import serialize
logging.basicConfig(stream=sys.stderr, level=logging.INFO)
TEMPLATE_PATH = os.path.dirname(os.path.realpath(__file__))
LOG = logging.getLogger(__name__)
def render_template(template_filename, data):
env = jinja2.Environment(
loader=jinja2.FileSystemLoader(TEMPLATE_PATH),
block_start_string=r"\code{",
block_end_string="}",
variable_start_string=r"\jvar{",
variable_end_string="}",
comment_start_string=r"\#{",
comment_end_string="}",
line_statement_prefix="%!!",
line_comment_prefix="%#",
trim_blocks=True,
autoescape=False,
)
return env.get_template(template_filename).render(data)
def ingest_data(fo):
data = {}
for line in fo.readlines():
data.update(serialize.deserialize(line))
return data
if __name__ == "__main__":
data = ingest_data(sys.stdin)
print(render_template(sys.argv[1], data))