~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to serve-branches

  • Committer: Matt Nordhoff
  • Date: 2009-06-09 03:41:07 UTC
  • mfrom: (345.2.8 valid-feed)
  • Revision ID: mnordhoff@mattnordhoff.com-20090609034107-khjku04mzj36vumr
Make the Atom feeds (nearly) valid (bug #247162)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env python
 
2
#
 
3
# Copyright (C) 2008, 2009 Canonical Ltd
 
4
#
2
5
# This program is free software; you can redistribute it and/or modify
3
6
# it under the terms of the GNU General Public License as published by
4
7
# the Free Software Foundation; either version 2 of the License, or
20
23
import sys
21
24
 
22
25
from bzrlib.plugin import load_plugins
 
26
from bzrlib.transport import get_transport
23
27
 
24
28
from paste import httpserver
25
29
from paste.httpexceptions import HTTPExceptionHandler, HTTPInternalServerError
26
30
from paste.translogger import TransLogger
27
31
 
28
32
from loggerhead import __version__
29
 
from loggerhead.apps.filesystem import (
30
 
    BranchesFromFileSystemRoot, UserBranchesFromFileSystemRoot)
 
33
from loggerhead.apps.transport import (
 
34
    BranchesFromTransportRoot, UserBranchesFromTransportRoot)
31
35
from loggerhead.config import LoggerheadConfig
32
36
from loggerhead.util import Reloader
33
37
from loggerhead.apps.error import ErrorHandlerApp
48
52
    else:
49
53
        path = '.'
50
54
 
51
 
    if not os.path.isdir(path):
52
 
        print "%s is not a directory" % path
53
 
        sys.exit(1)
 
55
    load_plugins()
 
56
 
 
57
    if config.get_option('allow_writes'):
 
58
        transport = get_transport(path)
 
59
    else:
 
60
        transport = get_transport('readonly+' + path)
54
61
 
55
62
    if config.get_option('trunk_dir') and not config.get_option('user_dirs'):
56
63
        print "--trunk-dir is only valid with --user-dirs"
66
73
        if not config.get_option('trunk_dir'):
67
74
            print "You didn't specify a directory for the trunk directories."
68
75
            sys.exit(1)
69
 
        app = UserBranchesFromFileSystemRoot(path, config)
 
76
        app = UserBranchesFromTransportRoot(transport, config)
70
77
    else:
71
 
        app = BranchesFromFileSystemRoot(path, config)
 
78
        app = BranchesFromTransportRoot(transport, config)
72
79
 
73
80
    # setup_logging()
74
81
    logging.basicConfig()
86
93
    logfile.setLevel(logging.DEBUG)
87
94
    logger.addHandler(logfile)
88
95
 
89
 
    if config.get_option('memory_profile'):
90
 
        memprofile = logging.getLogger('loggerhead-memprofile')
91
 
        memprofile.setLevel(logging.DEBUG)
92
 
        memprofile.addHandler(logging.FileHandler('loggerhead-memprofile'))
93
 
 
94
96
    # setup_logging() #end
95
97
 
96
 
    app = TransLogger(app, logger=logger)
97
98
    if config.get_option('profile'):
98
99
        from loggerhead.middleware.profile import LSProfMiddleware
99
100
        app = LSProfMiddleware(app)
100
101
    if config.get_option('memory_profile'):
101
 
        from loggerhead.middleware.profile import MemoryProfileMiddleware
102
 
        app = MemoryProfileMiddleware(app)
 
102
        from dozer import Dozer
 
103
        app = Dozer(app)
103
104
 
104
105
    if not config.get_option('user_prefix'):
105
106
        prefix = '/'
128
129
 
129
130
    app = HTTPExceptionHandler(app)
130
131
    app = ErrorHandlerApp(app)
 
132
    app = TransLogger(app, logger=logger)
131
133
 
132
134
    if not config.get_option('user_port'):
133
135
        port = '8080'
139
141
    else:
140
142
        host = config.get_option('user_host')
141
143
 
142
 
    load_plugins()
143
 
 
144
144
    httpserver.serve(app, host=host, port=port)
145
145
 
146
146