annotate bitsyblog/factory.py @ 73:e6055bf127eb

fix details necessary to make tweeting work...muahaha
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 08 Jul 2010 11:13:08 -0700
parents 0c98d1c2c6df
children 51b49bc484ff
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
45
c228832db770 fix blogme
k0s <k0scist@gmail.com>
parents: 41
diff changeset
1 from bitsyauth import BitsyAuth
0
e3823be6a423 initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff changeset
2 from bitsyblog import BitsyBlog, BitsierBlog
e3823be6a423 initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff changeset
3 from getpass import getpass
e3823be6a423 initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff changeset
4 from paste.httpexceptions import HTTPExceptionHandler
e3823be6a423 initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff changeset
5
52
3ddb2ca12178 allow for multiple template directories
k0s <k0scist@gmail.com>
parents: 50
diff changeset
6 # accepted configuration keys, e.g. 'bitsyblog.file_dir'
73
e6055bf127eb fix details necessary to make tweeting work...muahaha
Jeff Hammel <jhammel@mozilla.com>
parents: 71
diff changeset
7 config = set(BitsyBlog.defaults.keys())
e6055bf127eb fix details necessary to make tweeting work...muahaha
Jeff Hammel <jhammel@mozilla.com>
parents: 71
diff changeset
8 # config = set(['file_dir',
e6055bf127eb fix details necessary to make tweeting work...muahaha
Jeff Hammel <jhammel@mozilla.com>
parents: 71
diff changeset
9 # 'date_format',
e6055bf127eb fix details necessary to make tweeting work...muahaha
Jeff Hammel <jhammel@mozilla.com>
parents: 71
diff changeset
10 # 'subject',
e6055bf127eb fix details necessary to make tweeting work...muahaha
Jeff Hammel <jhammel@mozilla.com>
parents: 71
diff changeset
11 # 'n_links',
e6055bf127eb fix details necessary to make tweeting work...muahaha
Jeff Hammel <jhammel@mozilla.com>
parents: 71
diff changeset
12 # 'help_file',
e6055bf127eb fix details necessary to make tweeting work...muahaha
Jeff Hammel <jhammel@mozilla.com>
parents: 71
diff changeset
13 # 'header',
e6055bf127eb fix details necessary to make tweeting work...muahaha
Jeff Hammel <jhammel@mozilla.com>
parents: 71
diff changeset
14 # 'template_directories',
e6055bf127eb fix details necessary to make tweeting work...muahaha
Jeff Hammel <jhammel@mozilla.com>
parents: 71
diff changeset
15 # 'feed_items',
e6055bf127eb fix details necessary to make tweeting work...muahaha
Jeff Hammel <jhammel@mozilla.com>
parents: 71
diff changeset
16 # ])
70
f6a6a4b072e7 complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 59
diff changeset
17
f6a6a4b072e7 complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 59
diff changeset
18 def get_args(app_conf):
f6a6a4b072e7 complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 59
diff changeset
19 """return arguments for bitsyblog and its handlers"""
f6a6a4b072e7 complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 59
diff changeset
20 key_str = 'bitsyblog.'
f6a6a4b072e7 complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 59
diff changeset
21 bitsyblog_args = {}
f6a6a4b072e7 complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 59
diff changeset
22 handler_args = {}
f6a6a4b072e7 complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 59
diff changeset
23 for key, value in app_conf.items():
f6a6a4b072e7 complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 59
diff changeset
24 if key.startswith(key_str):
f6a6a4b072e7 complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 59
diff changeset
25 key = key.split(key_str, 1)[-1]
f6a6a4b072e7 complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 59
diff changeset
26 if key in config:
71
0c98d1c2c6df fix syntax errors
Jeff Hammel <jhammel@mozilla.com>
parents: 70
diff changeset
27 bitsyblog_args[key] = value
70
f6a6a4b072e7 complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 59
diff changeset
28 else:
f6a6a4b072e7 complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 59
diff changeset
29 if '.' in key:
f6a6a4b072e7 complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 59
diff changeset
30 section, key = key.split('.', 1)
f6a6a4b072e7 complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 59
diff changeset
31 handler_args.setdefault(section, {})[key] = value
f6a6a4b072e7 complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 59
diff changeset
32 return bitsyblog_args, handler_args
52
3ddb2ca12178 allow for multiple template directories
k0s <k0scist@gmail.com>
parents: 50
diff changeset
33
0
e3823be6a423 initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff changeset
34 def factory(global_conf, **app_conf):
e3823be6a423 initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff changeset
35 """make bitsyauth app and wrap it in middleware"""
70
f6a6a4b072e7 complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 59
diff changeset
36 bitsyblog_args, handler_args = get_args(app_conf)
71
0c98d1c2c6df fix syntax errors
Jeff Hammel <jhammel@mozilla.com>
parents: 70
diff changeset
37 app = BitsyBlog(bitsyblog_args, handler_args)
0
e3823be6a423 initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff changeset
38 secret = app_conf.get('secret', 'secret')
59
0af1f4ae328d fix a couple of basic things
egj@socialplanning.org
parents: 58
diff changeset
39 return BitsyAuth(HTTPExceptionHandler(app),
0af1f4ae328d fix a couple of basic things
egj@socialplanning.org
parents: 58
diff changeset
40 global_conf,
0af1f4ae328d fix a couple of basic things
egj@socialplanning.org
parents: 58
diff changeset
41 app.passwords,
0af1f4ae328d fix a couple of basic things
egj@socialplanning.org
parents: 58
diff changeset
42 app.newuser,
0af1f4ae328d fix a couple of basic things
egj@socialplanning.org
parents: 58
diff changeset
43 'bitsyblog',
0af1f4ae328d fix a couple of basic things
egj@socialplanning.org
parents: 58
diff changeset
44 secret)
0
e3823be6a423 initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff changeset
45
40
dc729d807cd5 whitespace cleanup
k0s <k0scist@gmail.com>
parents: 18
diff changeset
46
0
e3823be6a423 initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff changeset
47 def bitsierfactory(global_conf, **app_conf):
e3823be6a423 initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff changeset
48 """make single-user bitsyblog"""
70
f6a6a4b072e7 complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 59
diff changeset
49 bitsyblog_args, handler_args = get_args(app_conf)
f6a6a4b072e7 complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 59
diff changeset
50 user = app_conf['bitsyblog.user'] # ensure this exist
71
0c98d1c2c6df fix syntax errors
Jeff Hammel <jhammel@mozilla.com>
parents: 70
diff changeset
51 app = BitsierBlog(bitsyblog_args, handler_args)
0
e3823be6a423 initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff changeset
52 app.user = user
e3823be6a423 initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff changeset
53 secret = app_conf.get('secret', 'secret')
59
0af1f4ae328d fix a couple of basic things
egj@socialplanning.org
parents: 58
diff changeset
54 auth = BitsyAuth(HTTPExceptionHandler(app),
0af1f4ae328d fix a couple of basic things
egj@socialplanning.org
parents: 58
diff changeset
55 global_conf,
0af1f4ae328d fix a couple of basic things
egj@socialplanning.org
parents: 58
diff changeset
56 app.passwords,
0af1f4ae328d fix a couple of basic things
egj@socialplanning.org
parents: 58
diff changeset
57 newuser=None,
0af1f4ae328d fix a couple of basic things
egj@socialplanning.org
parents: 58
diff changeset
58 site=app_conf.get('site', 'bitsyblog'),
0af1f4ae328d fix a couple of basic things
egj@socialplanning.org
parents: 58
diff changeset
59 secret=secret)
0
e3823be6a423 initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff changeset
60 if not user in app.users:
e3823be6a423 initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff changeset
61 pw = getpass('Enter password for %s: ' % user)
e3823be6a423 initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff changeset
62 app.newuser(user, auth.hash(app.user, pw))
e3823be6a423 initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff changeset
63 return auth