27
27
"""Loggerhead web viewer for Bazaar branches.
29
This provides a new option "--http" to the "bzr serve" command, that
29
This provides a new option "--http" to the "bzr serve" command, that
30
30
starts a web server to browse the contents of a branch.
37
37
from bzrlib.api import require_any_api
39
require_any_api(bzrlib, [(1, 11, 0), (1, 13, 0), (1, 15, 0)])
39
require_any_api(bzrlib, [(1, 11, 0), (1, 13, 0)])
41
41
# TODO: This should provide a new type of server that can be used by bzr
42
42
# serve, maybe through a registry, rather than overriding the command. Though
47
47
# seems reasonable to have in-line here: bzrlib.commands and options are
48
48
# normally loaded, and the rest of loggerhead won't be loaded until serve
51
51
import bzrlib.builtins
52
52
from bzrlib.commands import get_cmd_object, register_command
53
53
from bzrlib.option import Option
71
71
import os.path, sys
72
72
sys.path.append(os.path.dirname(__file__))
74
from bzrlib.transport import get_transport
75
from loggerhead.apps.transport import BranchesFromTransportRoot
76
from loggerhead.config import LoggerheadConfig
74
from loggerhead.apps.filesystem import BranchesFromFileSystemRoot
77
75
from paste.httpexceptions import HTTPExceptionHandler
78
76
from paste.httpserver import serve
79
path = kw.get('directory', '.')
77
a = HTTPExceptionHandler(BranchesFromFileSystemRoot('.'))
80
78
port = kw.get('port', DEFAULT_PORT)
81
79
# port might be an int already...
82
80
if isinstance(port, basestring) and ':' in port:
83
81
host, port = port.split(':')
86
argv = ['--host', host, '--port', str(port), path]
87
config = LoggerheadConfig(argv)
88
transport = get_transport(path)
89
app = BranchesFromTransportRoot(transport, config)
90
app = HTTPExceptionHandler(app)
91
serve(app, host=host, port=port)
84
serve(a, host=host, port=port)
93
86
super(cmd_serve, self).run(*args, **kw)