~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: Matt Nordhoff
  • Date: 2009-05-17 13:03:04 UTC
  • mto: This revision was merged to the branch mainline in revision 351.
  • Revision ID: mnordhoff@mattnordhoff.com-20090517130304-z1ryqw3pmqjvsbzi
Support "bzr serve"'s --directory argument.

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, 11, 0), (1, 13, 0)])
 
39
    require_any_api(bzrlib, [(1, 11, 0), (1, 13, 0), (1, 15, 0)])
40
40
 
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
71
71
                import os.path, sys
72
72
                sys.path.append(os.path.dirname(__file__))
73
73
 
74
 
                from loggerhead.apps.filesystem import BranchesFromFileSystemRoot
 
74
                from bzrlib.transport import get_transport
 
75
                from loggerhead.apps.transport import BranchesFromTransportRoot
 
76
                from loggerhead.config import LoggerheadConfig
75
77
                from paste.httpexceptions import HTTPExceptionHandler
76
78
                from paste.httpserver import serve
77
 
                a = HTTPExceptionHandler(BranchesFromFileSystemRoot('.'))
 
79
                path = kw.get('directory', '.')
78
80
                port = kw.get('port', DEFAULT_PORT)
79
81
                # port might be an int already...
80
82
                if isinstance(port, basestring) and ':' in port:
81
83
                    host, port = port.split(':')
82
84
                else:
83
85
                    host = '0.0.0.0'
84
 
                serve(a, host=host, port=port)
 
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)
85
92
            else:
86
93
                super(cmd_serve, self).run(*args, **kw)
87
94