annotate bitsyblog/factory.py @ 59:0af1f4ae328d

fix a couple of basic things
author egj@socialplanning.org
date Mon, 04 Jan 2010 03:12:04 +0000
parents b97d11e2cf41
children f6a6a4b072e7
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'
58
b97d11e2cf41 * document defaults
k0s <k0scist@gmail.com>
parents: 52
diff changeset
7 config = set(['file_dir',
b97d11e2cf41 * document defaults
k0s <k0scist@gmail.com>
parents: 52
diff changeset
8 'date_format',
b97d11e2cf41 * document defaults
k0s <k0scist@gmail.com>
parents: 52
diff changeset
9 'subject',
b97d11e2cf41 * document defaults
k0s <k0scist@gmail.com>
parents: 52
diff changeset
10 'n_links',
b97d11e2cf41 * document defaults
k0s <k0scist@gmail.com>
parents: 52
diff changeset
11 'help_file',
b97d11e2cf41 * document defaults
k0s <k0scist@gmail.com>
parents: 52
diff changeset
12 'header',
b97d11e2cf41 * document defaults
k0s <k0scist@gmail.com>
parents: 52
diff changeset
13 'template_directories',
b97d11e2cf41 * document defaults
k0s <k0scist@gmail.com>
parents: 52
diff changeset
14 'feed_items'])
52
3ddb2ca12178 allow for multiple template directories
k0s <k0scist@gmail.com>
parents: 50
diff changeset
15
0
e3823be6a423 initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff changeset
16 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
17 """make bitsyauth app and wrap it in middleware"""
e3823be6a423 initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff changeset
18 key_str = 'bitsyblog.%s'
e3823be6a423 initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff changeset
19 args = dict([ (key, app_conf[ key_str % key]) for key in config
e3823be6a423 initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff changeset
20 if app_conf.has_key(key_str % key) ])
e3823be6a423 initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff changeset
21 app = BitsyBlog(**args)
e3823be6a423 initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff changeset
22 secret = app_conf.get('secret', 'secret')
59
0af1f4ae328d fix a couple of basic things
egj@socialplanning.org
parents: 58
diff changeset
23 return BitsyAuth(HTTPExceptionHandler(app),
0af1f4ae328d fix a couple of basic things
egj@socialplanning.org
parents: 58
diff changeset
24 global_conf,
0af1f4ae328d fix a couple of basic things
egj@socialplanning.org
parents: 58
diff changeset
25 app.passwords,
0af1f4ae328d fix a couple of basic things
egj@socialplanning.org
parents: 58
diff changeset
26 app.newuser,
0af1f4ae328d fix a couple of basic things
egj@socialplanning.org
parents: 58
diff changeset
27 'bitsyblog',
0af1f4ae328d fix a couple of basic things
egj@socialplanning.org
parents: 58
diff changeset
28 secret)
0
e3823be6a423 initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff changeset
29
40
dc729d807cd5 whitespace cleanup
k0s <k0scist@gmail.com>
parents: 18
diff changeset
30
0
e3823be6a423 initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff changeset
31 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
32 """make single-user bitsyblog"""
e3823be6a423 initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff changeset
33 key_str = 'bitsyblog.%s'
e3823be6a423 initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff changeset
34 args = dict([ (key, app_conf[ key_str % key]) for key in config
e3823be6a423 initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff changeset
35 if app_conf.has_key(key_str % key) ])
e3823be6a423 initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff changeset
36 user = app_conf['bitsyblog.user']
e3823be6a423 initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff changeset
37 app = BitsierBlog(**args)
e3823be6a423 initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff changeset
38 app.user = user
e3823be6a423 initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff changeset
39 secret = app_conf.get('secret', 'secret')
59
0af1f4ae328d fix a couple of basic things
egj@socialplanning.org
parents: 58
diff changeset
40 auth = BitsyAuth(HTTPExceptionHandler(app),
0af1f4ae328d fix a couple of basic things
egj@socialplanning.org
parents: 58
diff changeset
41 global_conf,
0af1f4ae328d fix a couple of basic things
egj@socialplanning.org
parents: 58
diff changeset
42 app.passwords,
0af1f4ae328d fix a couple of basic things
egj@socialplanning.org
parents: 58
diff changeset
43 newuser=None,
0af1f4ae328d fix a couple of basic things
egj@socialplanning.org
parents: 58
diff changeset
44 site=app_conf.get('site', 'bitsyblog'),
0af1f4ae328d fix a couple of basic things
egj@socialplanning.org
parents: 58
diff changeset
45 secret=secret)
0
e3823be6a423 initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff changeset
46 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
47 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
48 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
49 return auth