~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to serve-branches

  • Committer: Martin Albisetti
  • Date: 2008-11-05 00:50:06 UTC
  • Revision ID: argentina@gmail.com-20081105005006-ydzve4evla71s9cm
Ehm, print statements shouldnt go into trunk.

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
 
 
26
24
from paste import httpserver
27
 
from paste.httpexceptions import HTTPExceptionHandler, HTTPInternalServerError
 
25
from paste.httpexceptions import HTTPExceptionHandler
28
26
from paste.translogger import TransLogger
29
27
 
30
28
from loggerhead import __version__
52
50
                      help="Host Loggerhead should listen on.")
53
51
    parser.add_option("--prefix", dest="user_prefix",
54
52
                      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.")
58
53
    parser.add_option("--reload", action="store_true", dest="reload",
59
54
                      help="Restarts the application when changing python"
60
55
                           " files. Only used for development purposes.")
118
113
    logfile.setLevel(logging.DEBUG)
119
114
    logger.addHandler(logfile)
120
115
    # setup_logging() #end
 
116
    app = ErrorHandlerApp(app)
 
117
    app = HTTPExceptionHandler(app)
121
118
    app = TransLogger(app, logger=logger)
122
 
    if options.profile:
123
 
        from loggerhead.middleware.profile import LSProfMiddleware
124
 
        app = LSProfMiddleware(app)
125
119
 
126
120
    if not options.user_prefix:
127
121
        prefix = '/'
128
122
    else:
129
123
        prefix = options.user_prefix
130
 
        if not prefix.startswith('/'):
131
 
            prefix = '/' + prefix
132
124
 
133
125
    try:
134
126
        from paste.deploy.config import PrefixMiddleware
135
127
    except ImportError:
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
        pass
148
129
    else:
149
130
        app = PrefixMiddleware(app, prefix=prefix)
150
131
 
151
 
    app = HTTPExceptionHandler(app)
152
 
    app = ErrorHandlerApp(app)
153
 
 
154
132
    if not options.user_port:
155
133
        port = '8080'
156
134
    else:
161
139
    else:
162
140
        host = options.user_host
163
141
 
164
 
    load_plugins()
165
 
 
166
142
    httpserver.serve(app, host=host, port=port)
167
143
 
168
144