summaryrefslogtreecommitdiffstats
path: root/render.py
blob: 39e06b166df26b1214f3c5126b3074d02c614cb1 (plain)
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
47
48
#!/usr/bin/python2

import yaml
import os
from jinja2 import Environment, FileSystemLoader

# configs
basepath="./data"
www_dir="./www" 

env = Environment( loader = FileSystemLoader('./templates'))
hosts = []

def load_yaml(path):
    with open(path) as f:
        return yaml.load(f)

hosts = load_yaml(os.path.join(basepath, "metadata", "hosts"))

data = []

for host in hosts['hosts']:

    host_data = load_yaml(os.path.join(basepath, host))
    template = env.get_template('host.html')

    print("Rendering host: " + host)
    url =  host + ".html"
    with open(os.path.join(www_dir, url),"w+") as f:
        f.write(template.render(**host_data))

    host_data['url'] = url 

    data.append(host_data)


template = env.get_template('index.html')


print("Rendering host index")

with open(os.path.join(www_dir, 'index.html'), "w+") as f:
    f.write(template.render(hosts=data))

print("done")