~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: Jelmer Vernooij
  • Date: 2009-06-02 00:09:55 UTC
  • mto: (359.3.1 hpss-writes)
  • mto: This revision was merged to the branch mainline in revision 367.
  • Revision ID: jelmer@samba.org-20090602000955-91nohd46pktp8j8k
Support serving branches over HTTP using the smart server protocol.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
    import bzrlib
37
37
    from bzrlib.api import require_any_api
38
38
 
39
 
    require_any_api(bzrlib, [(1, 13, 0), (1, 15, 0), (1, 16, 0), (1, 17, 0)])
 
39
    require_any_api(bzrlib, [(1, 11, 0), (1, 13, 0), (1, 15, 0)])
40
40
 
41
41
    # NB: Normally plugins should lazily load almost everything, but this
42
42
    # seems reasonable to have in-line here: bzrlib.commands and options are
43
43
    # normally loaded, and the rest of loggerhead won't be loaded until serve
44
44
    # --http is run.
45
 
 
 
45
        
46
46
    # transport_server_registry was added in bzr 1.16. When we drop support for
47
47
    # older releases, we can remove the code to override cmd_serve.
48
48
 
53
53
 
54
54
    DEFAULT_HOST = '0.0.0.0'
55
55
    DEFAULT_PORT = 8080
56
 
    HELP = ('Loggerhead, a web-based code viewer and server. (default port: %d)' %
 
56
    HELP = ('Loggerhead web-based code viewer and server. (default port: %d)' %
57
57
            (DEFAULT_PORT,))
58
58
 
59
59
    def serve_http(transport, host=None, port=None, inet=None):
60
60
        # loggerhead internal code will try to 'import loggerhead', so
61
 
        # let's put it on the path if we can't find it in the existing path
62
 
        try:
63
 
            import loggerhead
64
 
        except ImportError:
65
 
            import os.path, sys
66
 
            sys.path.append(os.path.dirname(__file__))
 
61
        # let's put it on the path
 
62
        import os.path, sys
 
63
        sys.path.append(os.path.dirname(__file__))
67
64
 
68
65
        from loggerhead.apps.transport import BranchesFromTransportRoot
69
66
        from loggerhead.config import LoggerheadConfig
73
70
            host = DEFAULT_HOST
74
71
        if port is None:
75
72
            port = DEFAULT_PORT
76
 
        argv = ['--host', host, '--port', str(port), '--', transport.base]
77
 
        if not transport.is_readonly():
78
 
            argv.insert(0, '--allow-writes')
 
73
        argv = ['--host', host, '--port', str(port), transport.base]
79
74
        config = LoggerheadConfig(argv)
80
75
        app = BranchesFromTransportRoot(transport, config)
81
76
        app = HTTPExceptionHandler(app)
99
94
            def run(self, *args, **kw):
100
95
                if 'http' in kw:
101
96
                    from bzrlib.transport import get_transport
102
 
                    allow_writes = kw.get('allow_writes', False)
103
97
                    path = kw.get('directory', '.')
104
98
                    port = kw.get('port', DEFAULT_PORT)
105
99
                    # port might be an int already...
107
101
                        host, port = port.split(':')
108
102
                    else:
109
103
                        host = DEFAULT_HOST
110
 
                    if allow_writes:
111
 
                        transport = get_transport(path)
112
 
                    else:
113
 
                        transport = get_transport('readonly+' + path)
 
104
                    transport = get_transport(path)
114
105
                    serve_http(transport, host, port)
115
106
                else:
116
107
                    super(cmd_serve, self).run(*args, **kw)