22
22
from optparse import OptionParser
24
from bzrlib.plugin import load_plugins
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
30
28
from loggerhead import __version__
46
44
parser.add_option("--trunk-dir", metavar="DIR",
47
45
help="The directory that contains the trunk branches.")
48
46
parser.add_option("--port", dest="user_port",
49
help=("Port Loggerhead should listen on "
50
"(defaults to 8080)."))
47
help="Port Loggerhead should listen on (defaults to 8080).")
51
48
parser.add_option("--host", dest="user_host",
52
49
help="Host Loggerhead should listen on.")
53
50
parser.add_option("--prefix", dest="user_prefix",
54
51
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
52
parser.add_option("--reload", action="store_true", dest="reload",
59
53
help="Restarts the application when changing python"
60
54
" files. Only used for development purposes.")
118
112
logfile.setLevel(logging.DEBUG)
119
113
logger.addHandler(logfile)
120
114
# setup_logging() #end
115
app = ErrorHandlerApp(app)
116
app = HTTPExceptionHandler(app)
121
117
app = TransLogger(app, logger=logger)
123
from loggerhead.middleware.profile import LSProfMiddleware
124
app = LSProfMiddleware(app)
126
119
if not options.user_prefix:
129
122
prefix = options.user_prefix
130
if not prefix.startswith('/'):
131
prefix = '/' + prefix
134
125
from paste.deploy.config import PrefixMiddleware
135
126
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
145
return app(environ, start_response)
147
app = check_not_proxied(app)
149
129
app = PrefixMiddleware(app, prefix=prefix)
151
app = HTTPExceptionHandler(app)
152
app = ErrorHandlerApp(app)
154
131
if not options.user_port: