2016-03-19 20:37:04 +00:00
|
|
|
import os
|
2016-04-06 18:38:45 +00:00
|
|
|
import yaml
|
2016-03-30 19:23:19 +00:00
|
|
|
|
2016-08-14 12:22:53 +00:00
|
|
|
|
2016-04-06 18:38:45 +00:00
|
|
|
def merge(left, right):
|
|
|
|
for key in right:
|
|
|
|
if key in left:
|
|
|
|
if isinstance(left[key], dict) and isinstance(right[key], dict):
|
|
|
|
merge(left[key], right[key])
|
|
|
|
elif left[key] != right[key]:
|
|
|
|
left[key] = right[key]
|
|
|
|
else:
|
|
|
|
left[key] = right[key]
|
|
|
|
return left
|
|
|
|
|
2016-08-14 12:22:53 +00:00
|
|
|
|
2016-04-16 13:07:33 +00:00
|
|
|
def read_config():
|
|
|
|
with open('../config.yaml.dist') as handle:
|
|
|
|
ret = yaml.load(handle.read())
|
2016-04-06 18:38:45 +00:00
|
|
|
if os.path.exists('../config.yaml'):
|
|
|
|
with open('../config.yaml') as handle:
|
2016-04-16 13:07:33 +00:00
|
|
|
ret = merge(ret, yaml.load(handle.read()))
|
|
|
|
return ret
|
|
|
|
|
2016-08-14 12:22:53 +00:00
|
|
|
|
|
|
|
config = read_config() # pylint: disable=invalid-name
|