diff options
author | raylu <raylu@gridium.com> | 2013-05-03 03:41:50 -0700 |
---|---|---|
committer | raylu <raylu@gridium.com> | 2013-10-19 18:21:46 -0700 |
commit | 224f66a77aa3afa5e06daec656ae97f6e31e0592 (patch) | |
tree | f36843c32143c401ec1c6dccd502cddcbba6017c /config.py | |
download | ykill-224f66a77aa3afa5e06daec656ae97f6e31e0592.tar.xz |
start over
Diffstat (limited to 'config.py')
-rw-r--r-- | config.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/config.py b/config.py new file mode 100644 index 0000000..1f9be4d --- /dev/null +++ b/config.py @@ -0,0 +1,29 @@ +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', + ]) + +class DBConfig(Config): + attrs = frozenset([ + 'host', + 'user', + 'password', + 'database', + ]) + +__doc = yaml.load(open('config.yaml', 'r')) +web = WebConfig(__doc['web']) +db = DBConfig(__doc['db']) |