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