Mercurial > bottledash
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 | 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 | 69 @route('/') |
70 @view('hello_template') | |
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 | 73 |
74 @route('/config') | |
75 def call_config(): | |
76 return 'Not implemented yet' | |
77 | |
78 | |
79 @route('/static/<filepath:path>') | |
80 def server_static(filepath): | |
81 return static_file(filepath, root='./static_files/') | |
82 | |
83 @error(404) | |
84 def error404(error): | |
85 return 'Nothing here, sorry <br /> 404' | |
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 | 89 run(host='localhost', port=8080, debug=True) |