annotate dash.py @ 6:3acc5164369e

resize content in height too
author sean
date Wed, 22 Jul 2015 10:47:55 +0200
parents c49f7fe82743
children c8cb2aa0b72c
rev   line source
4
3e66e2f92770 added LICENSE and license headers in the sourcecode. Added readme
sean
parents: 3
diff changeset
1 """
3e66e2f92770 added LICENSE and license headers in the sourcecode. Added readme
sean
parents: 3
diff changeset
2 This software is part of "Bottledash"
3e66e2f92770 added LICENSE and license headers in the sourcecode. Added readme
sean
parents: 3
diff changeset
3 author: sean engelhardt > sean.engelhardt@intevation.de
3e66e2f92770 added LICENSE and license headers in the sourcecode. Added readme
sean
parents: 3
diff changeset
4 license: GNU >= V2. See LICENSE for details
3e66e2f92770 added LICENSE and license headers in the sourcecode. Added readme
sean
parents: 3
diff changeset
5 """
3e66e2f92770 added LICENSE and license headers in the sourcecode. Added readme
sean
parents: 3
diff changeset
6
3
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
7 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
8 from bottle import template, run, static_file, error
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
9 import configparser
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
10 import os.path
0
e1264e58154c initial commpit
sean
parents:
diff changeset
11
3
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
12 CONFIG_FILE = "dash.conf"
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
13 tiles = []
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
14
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
15 def read_config():
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 if os.path.isfile(CONFIG_FILE) == False:
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
18 write_default_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 config = configparser.ConfigParser()
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
21 config.read(CONFIG_FILE)
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
22
5
c49f7fe82743 changed the grid layout to a more responsive and compatible self-calculating JS based version
sean
parents: 4
diff changeset
23
c49f7fe82743 changed the grid layout to a more responsive and compatible self-calculating JS based version
sean
parents: 4
diff changeset
24
3
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
25 #read the tiles
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
26 read_tiles_config(config)
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
27
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
28 def read_tiles_config(config):
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
29 for section in config.items():
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
30 if "tile" in section[0]:
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
31 tiles.append(section[1])
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
32 # print(tiles[0]["type"])
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 def write_default_config():
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
35 file = open("dash.conf", "w")
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
36 file.write("""
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
37
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
38 ### bottledash default configuration
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
39 ### created by sean engelhardt >sean.engelhardt@intevation.de
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
40 ### license: GNU GPL >= v2
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 ### Usage:
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
43 ### define the tiles for the dashboard in sections
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
44 ###
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
45 ### options for tiles:
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
46 ###
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
47 ### type
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
48 ### values: mon, d3.js
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
49 ###
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
50 ### source (only if type = mon)
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
51 ### value: IP or FQDN
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
52 ### status
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
53 ###
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
54 ### 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
55 ### values: up, down
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
56 ###
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
57 ### example:
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
58 ### [tile1]
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
59 ### type=mon
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
60 ### source=192.168.0.2
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
61 ### status=up
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
62
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
63 [tile1]
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
64 type=mon
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
65 source=192.168.0.2
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
66 status=down
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 [tile2]
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
69 type=mon
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
70 source=192.168.2.1
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
71 status=up
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
72 """)
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
73 file.close()
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
74
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
75 ##Bottle
0
e1264e58154c initial commpit
sean
parents:
diff changeset
76 @route('/')
e1264e58154c initial commpit
sean
parents:
diff changeset
77 @view('hello_template')
e1264e58154c initial commpit
sean
parents:
diff changeset
78 def call_dashboard():
3
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
79 return dict(tiles=tiles)
0
e1264e58154c initial commpit
sean
parents:
diff changeset
80
e1264e58154c initial commpit
sean
parents:
diff changeset
81 @route('/config')
e1264e58154c initial commpit
sean
parents:
diff changeset
82 def call_config():
e1264e58154c initial commpit
sean
parents:
diff changeset
83 return 'Not implemented yet'
e1264e58154c initial commpit
sean
parents:
diff changeset
84
e1264e58154c initial commpit
sean
parents:
diff changeset
85
e1264e58154c initial commpit
sean
parents:
diff changeset
86 @route('/static/<filepath:path>')
e1264e58154c initial commpit
sean
parents:
diff changeset
87 def server_static(filepath):
e1264e58154c initial commpit
sean
parents:
diff changeset
88 return static_file(filepath, root='./static_files/')
e1264e58154c initial commpit
sean
parents:
diff changeset
89
e1264e58154c initial commpit
sean
parents:
diff changeset
90 @error(404)
e1264e58154c initial commpit
sean
parents:
diff changeset
91 def error404(error):
e1264e58154c initial commpit
sean
parents:
diff changeset
92 return 'Nothing here, sorry <br /> 404'
e1264e58154c initial commpit
sean
parents:
diff changeset
93
3
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
94 read_config()
3f5bcad45756 pars a .conf | dynamic adding of divs | dynamiv VP scaling
sean
parents: 0
diff changeset
95 print(tiles)
0
e1264e58154c initial commpit
sean
parents:
diff changeset
96 run(host='localhost', port=8080, debug=True)
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)