config.py

changeset 33
91421eeb4426
parent 31
b4b4bb7a2ec5
child 34
9fce700d42de
equal deleted inserted replaced
32:06fc14211ba9 33:91421eeb4426
4 # 4 #
5 5
6 import yaml 6 import yaml
7 import io 7 import io
8 import os 8 import os
9 import xdg
10 import string 9 import string
11 import logging 10 import logging
12 from functools import reduce 11 from functools import reduce
13 12
14 logger=logging.getLogger(__name__) 13 logger=logging.getLogger(__name__)
35 'create_parameters': [], 34 'create_parameters': [],
36 'prune_parameters': [], 35 'prune_parameters': [],
37 } 36 }
38 } 37 }
39 38
39 #
40 # Branding
41 #
42
43 appname="borgend"
44 appname_stylised="Borgend"
45
46 #
47 # Locations
48 #
49
50 if False:
51 import xdg
52 cfgfile=os.path.join(xdg.XDG_CONFIG_HOME, appname, "config.yaml")
53 logs_location=os.path.join(xdg.XDG_DATA_HOME, appname, "logs")
54 else:
55 import rumps
56 __base=rumps.application_support(appname)
57 cfgfile=os.path.join(__base, "config.yaml")
58 logs_location=os.path.join(__base, "logs")
40 59
41 # 60 #
42 # Type checking etc. 61 # Type checking etc.
43 # 62 #
44 63
122 else: 141 else:
123 out=cfg 142 out=cfg
124 143
125 return out 144 return out
126 145
127 cfgfile=os.path.join(xdg.XDG_CONFIG_HOME, "borgend", "config.yaml") 146 if not (os.path.exists(cfgfile) and os.path.isfile(cfgfile)):
147 raise SystemExit("Configuration file required: %s" % cfgfile)
128 148
129 logger.info("Reading configuration file %s" % cfgfile) 149 logger.info("Reading configuration %s missing" % cfgfile)
130
131 if not (os.path.exists(cfgfile) and os.path.isfile(cfgfile)):
132 raise SystemExit('Configuration file required: {cfgfile}')
133 150
134 with io.open(cfgfile, 'r') as file: 151 with io.open(cfgfile, 'r') as file:
135 settings=expand_env(yaml.load(file), os.environ); 152 settings=expand_env(yaml.load(file), os.environ);
136 153
137 # 154 #

mercurial