diff options
Diffstat (limited to 'render.py')
-rw-r--r-- | render.py | 27 |
1 files changed, 19 insertions, 8 deletions
@@ -3,10 +3,7 @@ import yaml import os import jinja2 - -# config -DATAPATH = "./data" -WWW_DIR = "./www" +import optparse class Renderer: def __init__(self, output_dir): @@ -32,16 +29,30 @@ class Renderer: self._render('index.html', 'index.html', hosts=data) def load_yaml(*args): - with open(os.path.join(DATAPATH, *args)) as infile: + with open(os.path.join(*args)) as infile: return yaml.load(infile) def main(): - renderer = Renderer(WWW_DIR) - hosts = load_yaml("metadata", "hosts") + basename = os.path.dirname(os.path.realpath(__file__)) + optparser = optparse.OptionParser() + optparser.add_option("-o", "--output", + help="write rendered hostinfo files DEST_DIR", + metavar="DEST_DIR", + default=os.path.join(basename,"htdocs")) + + optparser.add_option("-s", "--source", + help="read yaml encoded hostinfo data from SRC_DIR", + metavar="SRC_DIR", + default=os.path.join(basename,"data")) + + (options, _ ) = optparser.parse_args() + + renderer = Renderer(options.output) + hosts = load_yaml(options.source, "metadata", "hosts") data = [] for host in sorted(hosts['hosts']): - hostdata = load_yaml(host) + hostdata = load_yaml(options.source, host) renderer.host(host, hostdata) data.append(hostdata) |