diff dash.py @ 3:3f5bcad45756

pars a .conf | dynamic adding of divs | dynamiv VP scaling
author sean
date Wed, 15 Jul 2015 14:06:03 +0200
parents e1264e58154c
children 3e66e2f92770
line wrap: on
line diff
--- a/dash.py	Sun Jul 12 18:00:57 2015 +0200
+++ b/dash.py	Wed Jul 15 14:06:03 2015 +0200
@@ -1,9 +1,75 @@
-from bottle import get, post, request, view, response, route, template, run, static_file, error
+from bottle import get, post, request, view, response, route
+from bottle import template, run, static_file, error
+import configparser
+import os.path
 
+CONFIG_FILE = "dash.conf"
+tiles = []
+
+def read_config():
+
+    if os.path.isfile(CONFIG_FILE) == False:
+        write_default_config()
+
+    config = configparser.ConfigParser()
+    config.read(CONFIG_FILE)
+
+    #read the tiles
+    read_tiles_config(config)
+
+def read_tiles_config(config):
+    for section in config.items():
+        if "tile" in section[0]:
+            tiles.append(section[1])
+    # print(tiles[0]["type"])
+
+def write_default_config():
+    file = open("dash.conf", "w")
+    file.write("""
+
+### bottledash default configuration
+### created by sean engelhardt >sean.engelhardt@intevation.de
+### license: GNU GPL >= v2
+###
+### Usage:
+### define the tiles for the dashboard in sections
+###
+### options for tiles:
+###
+### type
+### values: mon, d3.js
+###
+### source (only if type = mon)
+### value: IP or FQDN
+### status
+###
+### status (for debug purpose only | only if type = mon)
+### values: up, down
+###
+### example:
+### [tile1]
+### type=mon
+### source=192.168.0.2
+### status=up
+
+[tile1]
+type=mon
+source=192.168.0.2
+status=down
+
+[tile2]
+type=mon
+source=192.168.2.1
+status=up
+""")
+    file.close()
+
+
+##Bottle
 @route('/')
 @view('hello_template')
 def call_dashboard():
-    return dict()
+    return dict(tiles=tiles)
 
 @route('/config')
 def call_config():
@@ -18,5 +84,6 @@
 def error404(error):
     return 'Nothing here, sorry <br /> 404'
 
-
+read_config()
+print(tiles)
 run(host='localhost', port=8080, debug=True)
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)