From 501692e33fd9834c75b2fa33e83edc67513ec8ad Mon Sep 17 00:00:00 2001 From: yves Date: Wed, 22 May 2013 14:28:39 +0200 Subject: render: add optparser --- render.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/render.py b/render.py index 3715b80..18d1174 100644 --- a/render.py +++ b/render.py @@ -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) -- cgit v1.2.3-1-g7c22