comparison bitsyblog/factory.py @ 0:e3823be6a423

initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
author k0s <k0scist@gmail.com>
date Sat, 12 Sep 2009 16:06:57 -0400
parents
children c293bcbe6e03
comparison
equal deleted inserted replaced
-1:000000000000 0:e3823be6a423
1 from bitsyauth import BitsyAuth
2 from bitsyblog import BitsyBlog, BitsierBlog
3 from getpass import getpass
4 from paste.httpexceptions import HTTPExceptionHandler
5
6 def factory(global_conf, **app_conf):
7 """make bitsyauth app and wrap it in middleware"""
8
9 config = [ 'file_dir', 'date_format', 'subject', 'n_links', 'help_file' ]
10 key_str = 'bitsyblog.%s'
11 args = dict([ (key, app_conf[ key_str % key]) for key in config
12 if app_conf.has_key(key_str % key) ])
13
14 app = BitsyBlog(**args)
15 secret = app_conf.get('secret', 'secret')
16 return BitsyAuth(HTTPExceptionHandler(app), global_conf, app.passwords, app.newuser, 'bitsyblog', secret)
17
18 # TODO: use wsgifilter.proxyapp.DebugHeaders to debug the headers apache
19 # doesn't like
20
21 def bitsierfactory(global_conf, **app_conf):
22 """make single-user bitsyblog"""
23 config = [ 'file_dir', 'date_format', 'subject', 'n_links', 'help_file' ]
24 key_str = 'bitsyblog.%s'
25 args = dict([ (key, app_conf[ key_str % key]) for key in config
26 if app_conf.has_key(key_str % key) ])
27
28 user = app_conf['bitsyblog.user']
29 app = BitsierBlog(**args)
30 app.user = user
31 secret = app_conf.get('secret', 'secret')
32 auth = BitsyAuth(HTTPExceptionHandler(app), global_conf, app.passwords, newuser=None, site='bitsyblog', secret=secret)
33 if not user in app.users:
34 pw = getpass('Enter password for %s: ' % user)
35 app.newuser(user, auth.hash(app.user, pw))
36 return auth