~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead.wsgi

  • Committer: Martin Pool
  • Date: 2011-11-25 02:58:16 UTC
  • mfrom: (459.2.16 240580-tarball)
  • Revision ID: mbp@canonical.com-20111125025816-25raz1nxcw17q30o
Add download-tarball support

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python -tt
2
 
# This program is free software; you can redistribute it and/or modify
3
 
# it under the terms of the GNU General Public License as published by
4
 
# the Free Software Foundation; either version 2 of the License, or
5
 
# (at your option) any later version.
6
 
#
7
 
# This program is distributed in the hope that it will be useful,
8
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 
# GNU General Public License for more details.
11
 
#
12
 
# You should have received a copy of the GNU General Public License
13
 
# along with this program; if not, write to the Free Software
14
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 
 
16
 
 
17
 
import sys
18
 
import os
19
 
import pwd
20
 
sys.path.insert(0, os.path.dirname(__file__))
21
 
 
22
 
from paste.httpexceptions import HTTPExceptionHandler
23
 
from loggerhead.apps.transport import BranchesFromTransportRoot
24
 
from loggerhead.apps.error import ErrorHandlerApp
25
 
from loggerhead.config import LoggerheadConfig
26
 
from bzrlib import config as bzrconfig
27
 
from paste.deploy.config import PrefixMiddleware
28
 
from bzrlib.plugin import load_plugins
29
 
 
30
 
class NotConfiguredError(Exception):
31
 
    pass
32
 
 
33
 
 
34
 
load_plugins()
35
 
config = LoggerheadConfig()
36
 
prefix = config.get_option('user_prefix') or ''
37
 
# Note we could use LoggerheadConfig here if it didn't fail when a
38
 
# config option is not also a commandline option
39
 
root_dir = bzrconfig.GlobalConfig().get_user_option('http_root_dir')
40
 
if not root_dir:
41
 
    raise NotConfiguredError('You must have a ~/.bazaar/bazaar.conf file for'
42
 
            ' %(user)s with http_root_dir set to the base directory you want'
43
 
            ' to serve bazaar repositories from' %
44
 
            {'user': pwd.getpwuid(os.geteuid()).pw_name})
45
 
prefix = prefix.encode('utf-8', 'ignore')
46
 
root_dir = root_dir.encode('utf-8', 'ignore')
47
 
app = BranchesFromTransportRoot(root_dir, config)
48
 
app = PrefixMiddleware(app, prefix=prefix)
49
 
app = HTTPExceptionHandler(app)
50
 
application = ErrorHandlerApp(app)