~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to serve-branches

  • Committer: Michael Hudson
  • Date: 2009-03-19 21:50:09 UTC
  • mfrom: (312.1.3 concurrency-thoughts)
  • Revision ID: michael.hudson@canonical.com-20090319215009-jv7zm2txj7ibra7w
use a more optimistic approach to concurrency around the filechanges cache

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
from optparse import OptionParser
23
23
 
 
24
from bzrlib.plugin import load_plugins
 
25
 
24
26
from paste import httpserver
25
 
from paste.httpexceptions import HTTPExceptionHandler
 
27
from paste.httpexceptions import HTTPExceptionHandler, HTTPInternalServerError
26
28
from paste.translogger import TransLogger
27
29
 
28
30
from loggerhead import __version__
44
46
    parser.add_option("--trunk-dir", metavar="DIR",
45
47
                      help="The directory that contains the trunk branches.")
46
48
    parser.add_option("--port", dest="user_port",
47
 
                      help="Port Loggerhead should listen on (defaults to 8080).")
 
49
                      help=("Port Loggerhead should listen on "
 
50
                            "(defaults to 8080)."))
48
51
    parser.add_option("--host", dest="user_host",
49
52
                      help="Host Loggerhead should listen on.")
50
53
    parser.add_option("--prefix", dest="user_prefix",
51
54
                      help="Specify host prefix.")
 
55
    parser.add_option("--profile", action="store_true", dest="profile",
 
56
                      help="Generate callgrind profile data to "
 
57
                        "%d-stats.callgrind on each request.")
52
58
    parser.add_option("--reload", action="store_true", dest="reload",
53
59
                      help="Restarts the application when changing python"
54
60
                           " files. Only used for development purposes.")
112
118
    logfile.setLevel(logging.DEBUG)
113
119
    logger.addHandler(logfile)
114
120
    # setup_logging() #end
115
 
    app = ErrorHandlerApp(app)
116
 
    app = HTTPExceptionHandler(app)
117
121
    app = TransLogger(app, logger=logger)
 
122
    if options.profile:
 
123
        from loggerhead.middleware.profile import LSProfMiddleware
 
124
        app = LSProfMiddleware(app)
118
125
 
119
126
    if not options.user_prefix:
120
127
        prefix = '/'
121
128
    else:
122
129
        prefix = options.user_prefix
 
130
        if not prefix.startswith('/'):
 
131
            prefix = '/' + prefix
123
132
 
124
133
    try:
125
134
        from paste.deploy.config import PrefixMiddleware
126
135
    except ImportError:
127
 
        pass
 
136
        cant_proxy_correctly_message = (
 
137
            'Unsupported configuration: PasteDeploy not available, but '
 
138
            'loggerhead appears to be behind a proxy.')
 
139
        def check_not_proxied(app):
 
140
            def wrapped(environ, start_response):
 
141
                if 'HTTP_X_FORWARDED_SERVER' in environ:
 
142
                    exc = HTTPInternalServerError()
 
143
                    exc.explanation = cant_proxy_correctly_message
 
144
                    raise exc
 
145
                return app(environ, start_response)
 
146
            return wrapped
 
147
        app = check_not_proxied(app)
128
148
    else:
129
149
        app = PrefixMiddleware(app, prefix=prefix)
130
150
 
 
151
    app = HTTPExceptionHandler(app)
 
152
    app = ErrorHandlerApp(app)
 
153
 
131
154
    if not options.user_port:
132
155
        port = '8080'
133
156
    else:
138
161
    else:
139
162
        host = options.user_host
140
163
 
 
164
    load_plugins()
 
165
 
141
166
    httpserver.serve(app, host=host, port=port)
142
167
 
143
168