-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender.py
More file actions
31 lines (23 loc) · 799 Bytes
/
render.py
File metadata and controls
31 lines (23 loc) · 799 Bytes
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
#!/usr/bin/env/python
import sys
import re
from jinja2 import Environment, FileSystemLoader
import yaml
from bracket_expansion import *
from pprint import pprint
import os
os.system('cls' if os.name == 'nt' else 'clear')
trim = True
if (len(sys.argv) > 2):
trim = sys.argv[2] != 'notrim'
ENV = Environment(loader=FileSystemLoader('.'),trim_blocks=trim,lstrip_blocks=trim)
ENV.filters['bracket_expansion'] = bracket_expansion
filename = re.sub("\.$","",sys.argv[1])
print ('--- Reading YAML file '+filename+'.yml ---')
with open(filename + '.yml') as _: yamldict = yaml.load(_)
print ('--- YAML dictionary in '+filename+'.yml ---')
pprint(yamldict)
print
print ('--- Rendering template '+filename+'.j2 ---')
template = ENV.get_template(filename + ".j2")
print(template.render(**yamldict))