From 224f66a77aa3afa5e06daec656ae97f6e31e0592 Mon Sep 17 00:00:00 2001 From: raylu Date: Fri, 3 May 2013 03:41:50 -0700 Subject: start over --- config.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 config.py (limited to 'config.py') 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']) -- cgit v1.2.3