config.py

changeset 79
b075b3db3044
parent 74
4f56142e7497
equal deleted inserted replaced
78:83b43987e61e 79:b075b3db3044
8 import os 8 import os
9 import string 9 import string
10 import logging 10 import logging
11 import platform 11 import platform
12 from functools import reduce 12 from functools import reduce
13 import borgend 13 import loggers
14 import branding
15 import locations
14 16
15 logger=borgend.logger.getChild(__name__) 17 logger=loggers.get(__name__)
16 18
17 # 19 #
18 # Defaults 20 # Defaults
19 # 21 #
20 22
35 'common_parameters': [], 37 'common_parameters': [],
36 'create_parameters': [], 38 'create_parameters': [],
37 'prune_parameters': [], 39 'prune_parameters': [],
38 } 40 }
39 } 41 }
40
41 #
42 # Locations
43 #
44
45 if platform.system()!='Darwin':
46 import xdg
47 cfgfile=os.path.join(xdg.XDG_CONFIG_HOME, borgend.appname, "config.yaml")
48 logs_dir=os.path.join(xdg.XDG_DATA_HOME, borgend.appname, "logs")
49 else:
50 import rumps
51 __base=rumps.application_support(borgend.appname)
52 cfgfile=os.path.join(__base, "config.yaml")
53 logs_dir=os.path.join(__base, "logs")
54 42
55 # 43 #
56 # Type checking etc. 44 # Type checking etc.
57 # 45 #
58 46
154 else: 142 else:
155 out=cfg 143 out=cfg
156 144
157 return out 145 return out
158 146
159 if not (os.path.exists(cfgfile) and os.path.isfile(cfgfile)): 147 if not (os.path.exists(locations.cfgfile) and os.path.isfile(locations.cfgfile)):
160 raise SystemExit("Configuration file required: %s" % cfgfile) 148 raise SystemExit("Configuration file required: %s" % locations.cfgfile)
161 149
162 logger.info("Reading configuration %s missing" % cfgfile) 150 logger.info("Reading configuration %s missing" % locations.cfgfile)
163 151
164 with io.open(cfgfile, 'r') as file: 152 with io.open(locations.cfgfile, 'r') as file:
165 settings=expand_env(yaml.load(file), os.environ); 153 settings=expand_env(yaml.load(file), os.environ);
166 154
167 # 155 #
168 # Verify basic settings 156 # Verify basic settings
169 # 157 #

mercurial