1
# Copyright 2009, 2010 Canonical Ltd
1
# Copyright 2009 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
30
30
starts a web server to browse the contents of a branch.
34
bzr_plugin_version as version_info,
35
bzr_compatible_versions,
33
version_info = (1, 17, 0)
38
35
if __name__ == 'bzrlib.plugins.loggerhead':
40
37
from bzrlib.api import require_any_api
42
require_any_api(bzrlib, bzr_compatible_versions)
39
require_any_api(bzrlib, [
40
(1, 13, 0), (1, 15, 0), (1, 16, 0), (1, 17, 0), (1, 18, 0),
41
(2, 0, 0), (2, 1, 0), (2, 2, 0)])
44
43
# NB: Normally plugins should lazily load almost everything, but this
45
44
# seems reasonable to have in-line here: bzrlib.commands and options are
59
58
HELP = ('Loggerhead, a web-based code viewer and server. (default port: %d)' %
62
def setup_logging(config):
66
logger = logging.getLogger('loggerhead')
67
handler = logging.StreamHandler(sys.stderr)
68
handler.setLevel(logging.DEBUG)
69
logger.addHandler(handler)
70
logging.getLogger('simpleTAL').addHandler(handler)
71
logging.getLogger('simpleTALES').addHandler(handler)
74
def _ensure_loggerhead_path():
75
"""Ensure that you can 'import loggerhead' and get the root."""
61
def serve_http(transport, host=None, port=None, inet=None):
62
from paste.httpexceptions import HTTPExceptionHandler
63
from paste.httpserver import serve
76
65
# loggerhead internal code will try to 'import loggerhead', so
77
66
# let's put it on the path if we can't find it in the existing path
79
import loggerhead.apps.transport
80
69
except ImportError:
81
70
import os.path, sys
82
71
sys.path.append(os.path.dirname(__file__))
84
def serve_http(transport, host=None, port=None, inet=None):
85
from paste.httpexceptions import HTTPExceptionHandler
86
from paste.httpserver import serve
88
_ensure_loggerhead_path()
90
73
from loggerhead.apps.transport import BranchesFromTransportRoot
91
74
from loggerhead.config import LoggerheadConfig
98
81
if not transport.is_readonly():
99
82
argv.insert(0, '--allow-writes')
100
83
config = LoggerheadConfig(argv)
101
setup_logging(config)
102
84
app = BranchesFromTransportRoot(transport.base, config)
103
85
app = HTTPExceptionHandler(app)
104
86
serve(app, host=host, port=port)
138
120
super(cmd_serve, self).run(*args, **kw)
140
122
register_command(cmd_serve)
142
def load_tests(standard_tests, module, loader):
143
_ensure_loggerhead_path()
144
standard_tests.addTests(loader.loadTestsFromModuleNames(
145
['bzrlib.plugins.loggerhead.loggerhead.tests']))
146
return standard_tests