Mercurial > bottledash
comparison dash.py @ 8:8fc4db85f2f5
fixed a path error
author | sean |
---|---|
date | Wed, 29 Jul 2015 12:02:51 +0200 |
parents | c8cb2aa0b72c |
children | b06cb7fbf7f8 |
comparison
equal
deleted
inserted
replaced
7:c8cb2aa0b72c | 8:8fc4db85f2f5 |
---|---|
4 license: GNU >= V2. See LICENSE for details | 4 license: GNU >= V2. See LICENSE for details |
5 """ | 5 """ |
6 | 6 |
7 from bottle import get, post, request, view, response, route | 7 from bottle import get, post, request, view, response, route |
8 from bottle import template, run, static_file, error | 8 from bottle import template, run, static_file, error |
9 import configparser | 9 import os.path,sys,configparser |
10 import os.path | |
11 | 10 |
12 CONFIG_FILE = "dash.conf" | 11 CONFIG_FILE = "dash.conf" |
12 PATH = os.path.abspath(os.path.dirname(sys.argv[0])) | |
13 CONFIG_PATH = PATH + "/" + CONFIG_FILE | |
14 | |
13 tiles = [] | 15 tiles = [] |
14 settings = {} | 16 settings = {} |
15 | 17 |
16 default_settings = configparser.ConfigParser() | 18 default_settings = configparser.ConfigParser() |
17 default_settings['settings'] = {'show_top_bar': True} | 19 default_settings['settings'] = {'show_top_bar': True} |
18 | 20 |
19 ##read the config file. usually "dash.conf" | 21 ##read the config file. usually "dash.conf" |
22 | |
20 def read_config(): | 23 def read_config(): |
24 | |
25 # print(PATH) | |
21 global settings | 26 global settings |
22 | 27 |
23 if os.path.isfile(CONFIG_FILE) == False: | 28 if os.path.isfile(CONFIG_PATH) == False: |
24 write_default_config() | 29 write_default_config() |
25 | 30 |
31 print("read existing config file...") | |
26 config = configparser.ConfigParser() | 32 config = configparser.ConfigParser() |
27 config.read(CONFIG_FILE) | 33 config.read(CONFIG_PATH) |
28 | 34 |
29 for section in config.items(): | 35 for section in config.items(): |
30 if "tile" in section[0]: | 36 if "tile" in section[0]: |
31 tiles.append(section[1]) | 37 tiles.append(section[1]) |
32 | 38 |
38 except KeyError: | 44 except KeyError: |
39 settings = default_settings["settings"] | 45 settings = default_settings["settings"] |
40 | 46 |
41 ###write the default condfig file if there is none | 47 ###write the default condfig file if there is none |
42 def write_default_config(): | 48 def write_default_config(): |
43 file = open("dash.conf", "w") | 49 print("there is no Config file! Creating one...") |
50 file = open(CONFIG_PATH, "w") | |
44 file.write(""" | 51 file.write(""" |
45 ### bottledash default configuration | 52 ### bottledash default configuration |
46 ### created by sean engelhardt >sean.engelhardt@intevation.de | 53 ### created by sean engelhardt >sean.engelhardt@intevation.de |
47 ### license: GNU GPL >= v2. See LICENSE for details | 54 ### license: GNU GPL >= v2. See LICENSE for details |
48 ### | 55 ### |
131 def error404(error): | 138 def error404(error): |
132 return 'Nothing here, sorry <br /> 404' | 139 return 'Nothing here, sorry <br /> 404' |
133 | 140 |
134 read_config() | 141 read_config() |
135 # print(tiles) | 142 # print(tiles) |
136 run(host='localhost', port=8080, debug=True) | 143 # run(host='localhost', port=8080, debug=True) |