diff bitsyblog/factory.py @ 70:f6a6a4b072e7

complete overhaul to allow event handlers
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 07 Jul 2010 16:18:19 -0700
parents 0af1f4ae328d
children 0c98d1c2c6df
line wrap: on
line diff
--- a/bitsyblog/factory.py	Wed Jul 07 13:58:21 2010 -0700
+++ b/bitsyblog/factory.py	Wed Jul 07 16:18:19 2010 -0700
@@ -11,13 +11,28 @@
               'help_file', 
               'header', 
               'template_directories', 
-              'feed_items'])
+              'feed_items',
+              ])
+
+def get_args(app_conf):
+    """return arguments for bitsyblog and its handlers"""
+    key_str = 'bitsyblog.'
+    bitsyblog_args = {}
+    handler_args = {}
+    for key, value in app_conf.items():
+        if key.startswith(key_str):
+            key = key.split(key_str, 1)[-1]
+            if key in config:
+                bitysblog_args[key] = value
+        else:
+            if '.' in key:
+                section, key = key.split('.', 1)
+                handler_args.setdefault(section, {})[key] = value
+    return bitsyblog_args, handler_args
 
 def factory(global_conf, **app_conf):
     """make bitsyauth app and wrap it in middleware"""
-    key_str = 'bitsyblog.%s'
-    args = dict([ (key, app_conf[ key_str % key]) for key in config
-                  if app_conf.has_key(key_str % key) ])
+    bitsyblog_args, handler_args = get_args(app_conf)
     app = BitsyBlog(**args)
     secret = app_conf.get('secret', 'secret')
     return BitsyAuth(HTTPExceptionHandler(app), 
@@ -30,10 +45,8 @@
 
 def bitsierfactory(global_conf, **app_conf):
     """make single-user bitsyblog"""
-    key_str = 'bitsyblog.%s'
-    args = dict([ (key, app_conf[ key_str % key]) for key in config
-                  if app_conf.has_key(key_str % key) ])
-    user = app_conf['bitsyblog.user']
+    bitsyblog_args, handler_args = get_args(app_conf)
+    user = app_conf['bitsyblog.user'] # ensure this exist
     app = BitsierBlog(**args)
     app.user = user
     secret = app_conf.get('secret', 'secret')