~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead.wsgi

  • Committer: Toshio Kuratomi
  • Date: 2010-04-18 14:41:23 UTC
  • mto: (464.1.1 mod-wsgi)
  • mto: This revision was merged to the branch mainline in revision 465.
  • Revision ID: toshio@fedoraproject.org-20100418144123-c93a6zbtmxzid12g
Files to anable mod_wsgi

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python -tt
 
2
 
 
3
import sys
 
4
import os
 
5
import pwd
 
6
sys.path.insert(0, os.path.dirname(__file__))
 
7
 
 
8
from paste.httpexceptions import HTTPExceptionHandler
 
9
from loggerhead.apps.transport import BranchesFromTransportRoot
 
10
from loggerhead.apps.error import ErrorHandlerApp
 
11
from loggerhead.config import LoggerheadConfig
 
12
from bzrlib import config as bzrconfig
 
13
from paste.deploy.config import PrefixMiddleware
 
14
from bzrlib.plugin import load_plugins
 
15
 
 
16
class NotConfiguredError(Exception):
 
17
    pass
 
18
 
 
19
 
 
20
load_plugins()
 
21
config = LoggerheadConfig()
 
22
prefix = config.get_option('user_prefix') or ''
 
23
# Note we could use LoggerheadConfig here if it didn't fail when a
 
24
# config option is not also a commandline option
 
25
root_dir = bzrconfig.GlobalConfig().get_user_option('http_root_dir')
 
26
if not root_dir:
 
27
    raise NotConfiguredError('You must have a ~/.bazaar/bazaar.conf file for'
 
28
            ' %(user)s with http_root_dir set to the base directory you want'
 
29
            ' to serve bazaar repositories from' %
 
30
            {'user': pwd.getpwuid(os.geteuid()).pw_name})
 
31
prefix = prefix.encode('utf-8', 'ignore')
 
32
root_dir = root_dir.encode('utf-8', 'ignore')
 
33
app = BranchesFromTransportRoot(root_dir, config)
 
34
app = PrefixMiddleware(app, prefix=prefix)
 
35
app = HTTPExceptionHandler(app)
 
36
application = ErrorHandlerApp(app)