-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender.py
executable file
·46 lines (35 loc) · 1.04 KB
/
render.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
43
44
45
46
#!/usr/bin/python3
import pathlib
import jinja2
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser()
parser.add_argument(
"-b",
dest="base",
type=pathlib.Path,
default=pathlib.Path.cwd(),
help="Base directory with respect to which paths are resolved. This"
" defaults to the current working directory."
)
parser.add_argument(
"--staging",
default=False,
action='store_true',
help="Set the staging flag (this has to be handled by the template)."
)
parser.add_argument(
"template",
type=pathlib.Path,
help="Template to render"
)
parser.add_argument(
"output"
)
args = parser.parse_args()
loader = jinja2.FileSystemLoader(str(args.base.resolve()))
env = jinja2.Environment(loader=loader)
env.globals["staging"] = args.staging
tpl = env.get_template(str(args.template))
with open(args.output, "w", encoding="utf-8") as f:
f.write(tpl.render())