comparison 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
comparison
equal deleted inserted replaced
2:3671857d1dfe 3:3f5bcad45756
1 from bottle import get, post, request, view, response, route, template, run, static_file, error 1 from bottle import get, post, request, view, response, route
2 from bottle import template, run, static_file, error
3 import configparser
4 import os.path
2 5
6 CONFIG_FILE = "dash.conf"
7 tiles = []
8
9 def read_config():
10
11 if os.path.isfile(CONFIG_FILE) == False:
12 write_default_config()
13
14 config = configparser.ConfigParser()
15 config.read(CONFIG_FILE)
16
17 #read the tiles
18 read_tiles_config(config)
19
20 def read_tiles_config(config):
21 for section in config.items():
22 if "tile" in section[0]:
23 tiles.append(section[1])
24 # print(tiles[0]["type"])
25
26 def write_default_config():
27 file = open("dash.conf", "w")
28 file.write("""
29
30 ### bottledash default configuration
31 ### created by sean engelhardt >sean.engelhardt@intevation.de
32 ### license: GNU GPL >= v2
33 ###
34 ### Usage:
35 ### define the tiles for the dashboard in sections
36 ###
37 ### options for tiles:
38 ###
39 ### type
40 ### values: mon, d3.js
41 ###
42 ### source (only if type = mon)
43 ### value: IP or FQDN
44 ### status
45 ###
46 ### status (for debug purpose only | only if type = mon)
47 ### values: up, down
48 ###
49 ### example:
50 ### [tile1]
51 ### type=mon
52 ### source=192.168.0.2
53 ### status=up
54
55 [tile1]
56 type=mon
57 source=192.168.0.2
58 status=down
59
60 [tile2]
61 type=mon
62 source=192.168.2.1
63 status=up
64 """)
65 file.close()
66
67
68 ##Bottle
3 @route('/') 69 @route('/')
4 @view('hello_template') 70 @view('hello_template')
5 def call_dashboard(): 71 def call_dashboard():
6 return dict() 72 return dict(tiles=tiles)
7 73
8 @route('/config') 74 @route('/config')
9 def call_config(): 75 def call_config():
10 return 'Not implemented yet' 76 return 'Not implemented yet'
11 77
16 82
17 @error(404) 83 @error(404)
18 def error404(error): 84 def error404(error):
19 return 'Nothing here, sorry <br /> 404' 85 return 'Nothing here, sorry <br /> 404'
20 86
21 87 read_config()
88 print(tiles)
22 run(host='localhost', port=8080, debug=True) 89 run(host='localhost', port=8080, debug=True)
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)