summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryves <steve.harrison@gmx.net>2013-05-22 14:28:39 +0200
committeryves <steve.harrison@gmx.net>2013-05-22 14:28:39 +0200
commit501692e33fd9834c75b2fa33e83edc67513ec8ad (patch)
treedd9cc74cd5d4fffe9ebb30b6cf5154bfb57ade16
parentef8404ad29a9f1cb42d56d18a5f02cbe8b77daec (diff)
downloadwww-501692e33fd9834c75b2fa33e83edc67513ec8ad.tar.gz
www-501692e33fd9834c75b2fa33e83edc67513ec8ad.tar.bz2
www-501692e33fd9834c75b2fa33e83edc67513ec8ad.zip
render: add optparser
-rw-r--r--render.py27
1 files 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)