1
# Copyright 2009 Canonical Ltd
1
# Copyright 2009, 2010 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.
33
version_info = (1, 17, 0)
34
bzr_plugin_version as version_info,
35
bzr_compatible_versions,
35
38
if __name__ == 'bzrlib.plugins.loggerhead':
37
40
from bzrlib.api import require_any_api
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)])
42
require_any_api(bzrlib, bzr_compatible_versions)
43
44
# NB: Normally plugins should lazily load almost everything, but this
44
45
# seems reasonable to have in-line here: bzrlib.commands and options are
58
59
HELP = ('Loggerhead, a web-based code viewer and server. (default port: %d)' %
61
def serve_http(transport, host=None, port=None, inet=None):
62
from paste.httpexceptions import HTTPExceptionHandler
63
from paste.httpserver import serve
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."""
65
76
# loggerhead internal code will try to 'import loggerhead', so
66
77
# let's put it on the path if we can't find it in the existing path
79
import loggerhead.apps.transport
69
80
except ImportError:
70
81
import os.path, sys
71
82
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()
73
90
from loggerhead.apps.transport import BranchesFromTransportRoot
74
91
from loggerhead.config import LoggerheadConfig
81
98
if not transport.is_readonly():
82
99
argv.insert(0, '--allow-writes')
83
100
config = LoggerheadConfig(argv)
101
setup_logging(config)
84
102
app = BranchesFromTransportRoot(transport.base, config)
85
103
app = HTTPExceptionHandler(app)
86
104
serve(app, host=host, port=port)
120
138
super(cmd_serve, self).run(*args, **kw)
122
140
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