summaryrefslogtreecommitdiffstats
path: root/config.py
diff options
context:
space:
mode:
Diffstat (limited to 'config.py')
-rw-r--r--config.py29
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'])