-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.py
More file actions
46 lines (31 loc) · 870 Bytes
/
config.py
File metadata and controls
46 lines (31 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Python
import json
import logging
class config_helper_t:
def __init__(self):
self.loaded = False
self.settings = {}
def __getattr__(self, name):
return self.settings[name]
def __hasattr__(self, name):
return name in self.settings
def set_mode(self, key):
if self.loaded:
raise RuntimeError('set was called too many times')
d = None
with open('settings.json') as f:
d = json.load(f)
if key not in d:
raise ValueError('invalid config key: {}'.format(key))
self.settings = d['shared']
self.settings.update(d[key])
# secret
d = None
with open('settings_secret.json') as f:
d = json.load(f)
if key not in d:
raise ValueError('invalid config key: {}'.format(key))
self.settings.update(d[key])
logging.debug(self.settings)
self.loaded = True
config_helper = config_helper_t()