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
|
import yaml
class Config:
def __init__(self, cdict):
attrs = set(self.attrs) # copy and "unfreeze"
for k, v in cdict.items():
attrs.remove(k) # check if the key is allowed, mark it as present
setattr(self, k, v)
if len(attrs) != 0:
raise KeyError('missing required bot config keys: %s' % attrs)
class WebConfig(Config):
attrs = frozenset([
'port',
'host',
'cookie_secret',
'debug',
])
class DBConfig(Config):
attrs = frozenset([
'host',
'user',
'password',
'database',
])
__doc = yaml.load(open('config.yaml', 'r'))
web = WebConfig(__doc['web'])
db = DBConfig(__doc['db'])
|