sean@3: from bottle import get, post, request, view, response, route sean@3: from bottle import template, run, static_file, error sean@3: import configparser sean@3: import os.path sean@0: sean@3: CONFIG_FILE = "dash.conf" sean@3: tiles = [] sean@3: sean@3: def read_config(): sean@3: sean@3: if os.path.isfile(CONFIG_FILE) == False: sean@3: write_default_config() sean@3: sean@3: config = configparser.ConfigParser() sean@3: config.read(CONFIG_FILE) sean@3: sean@3: #read the tiles sean@3: read_tiles_config(config) sean@3: sean@3: def read_tiles_config(config): sean@3: for section in config.items(): sean@3: if "tile" in section[0]: sean@3: tiles.append(section[1]) sean@3: # print(tiles[0]["type"]) sean@3: sean@3: def write_default_config(): sean@3: file = open("dash.conf", "w") sean@3: file.write(""" sean@3: sean@3: ### bottledash default configuration sean@3: ### created by sean engelhardt >sean.engelhardt@intevation.de sean@3: ### license: GNU GPL >= v2 sean@3: ### sean@3: ### Usage: sean@3: ### define the tiles for the dashboard in sections sean@3: ### sean@3: ### options for tiles: sean@3: ### sean@3: ### type sean@3: ### values: mon, d3.js sean@3: ### sean@3: ### source (only if type = mon) sean@3: ### value: IP or FQDN sean@3: ### status sean@3: ### sean@3: ### status (for debug purpose only | only if type = mon) sean@3: ### values: up, down sean@3: ### sean@3: ### example: sean@3: ### [tile1] sean@3: ### type=mon sean@3: ### source=192.168.0.2 sean@3: ### status=up sean@3: sean@3: [tile1] sean@3: type=mon sean@3: source=192.168.0.2 sean@3: status=down sean@3: sean@3: [tile2] sean@3: type=mon sean@3: source=192.168.2.1 sean@3: status=up sean@3: """) sean@3: file.close() sean@3: sean@3: sean@3: ##Bottle sean@0: @route('/') sean@0: @view('hello_template') sean@0: def call_dashboard(): sean@3: return dict(tiles=tiles) sean@0: sean@0: @route('/config') sean@0: def call_config(): sean@0: return 'Not implemented yet' sean@0: sean@0: sean@0: @route('/static/') sean@0: def server_static(filepath): sean@0: return static_file(filepath, root='./static_files/') sean@0: sean@0: @error(404) sean@0: def error404(error): sean@0: return 'Nothing here, sorry
404' sean@0: sean@3: read_config() sean@3: print(tiles) sean@0: run(host='localhost', port=8080, debug=True)