~launchpad-pqm/launchpad/devel

7732.1.3 by Jonathan Lange
Get rid of the branchesdest config variable.
1
# Copyright 2004-2007, 2009 Canonical Ltd.  All rights reserved.
4277.4.12 by Jonathan Lange
Shift Launchpad server plugin around. Still no tests :(
2
4277.4.22 by Jonathan Lange
A tonne of docstrings and comments.
3
"""Bazaar plugin to run the smart server on Launchpad.
4
5
Cribbed from bzrlib.builtins.cmd_serve from Bazaar 0.16.
6
"""
4277.4.12 by Jonathan Lange
Shift Launchpad server plugin around. Still no tests :(
7
8
__metaclass__ = type
9
10
__all__ = ['cmd_launchpad_server']
11
12
4277.4.7 by Jonathan Lange
Add a sucky implementation of launchpad serving command.
13
import sys
14
4277.4.12 by Jonathan Lange
Shift Launchpad server plugin around. Still no tests :(
15
from bzrlib.commands import Command, register_command
4277.4.7 by Jonathan Lange
Add a sucky implementation of launchpad serving command.
16
from bzrlib.option import Option
8447.1.1 by Jonathan Lange
Clean up all of the pyflakes that we can find.
17
from bzrlib import lockdir, ui
4277.4.7 by Jonathan Lange
Add a sucky implementation of launchpad serving command.
18
4277.4.12 by Jonathan Lange
Shift Launchpad server plugin around. Still no tests :(
19
from bzrlib.smart import medium, server
8496.2.1 by Jonathan Lange
BZR_DEFAULT_* lives in medium, not transport.remote.
20
from bzrlib.transport import get_transport
4277.4.7 by Jonathan Lange
Add a sucky implementation of launchpad serving command.
21
22
4277.4.12 by Jonathan Lange
Shift Launchpad server plugin around. Still no tests :(
23
class cmd_launchpad_server(Command):
24
    """Run a Bazaar server that maps Launchpad branch URLs to the internal
25
    file-system format.
26
    """
4277.4.7 by Jonathan Lange
Add a sucky implementation of launchpad serving command.
27
4277.4.12 by Jonathan Lange
Shift Launchpad server plugin around. Still no tests :(
28
    aliases = ['lp-serve']
4277.4.7 by Jonathan Lange
Add a sucky implementation of launchpad serving command.
29
30
    takes_options = [
4277.4.12 by Jonathan Lange
Shift Launchpad server plugin around. Still no tests :(
31
        Option('inet',
32
               help='serve on stdin/out for use from inetd or sshd'),
4277.4.7 by Jonathan Lange
Add a sucky implementation of launchpad serving command.
33
        Option('port',
34
               help='listen for connections on nominated port of the form '
5520.1.4 by Aaron Bentley
Cleanup
35
                    '[hostname:]portnumber. Passing 0 as the port number will'
36
                    ' result in a dynamically allocated port. Default port is'
37
                    ' 4155.',
4277.4.7 by Jonathan Lange
Add a sucky implementation of launchpad serving command.
38
               type=str),
4330.4.36 by Jonathan Lange
Add a mirror_root parameter the rest of the way up the stack.
39
        Option('upload-directory',
40
               help='upload branches to this directory. Defaults to '
7732.1.2 by Jonathan Lange
Change the name of the config variable for the hosted area from
41
                    'config.codehosting.hosted_branches_root.',
4277.4.12 by Jonathan Lange
Shift Launchpad server plugin around. Still no tests :(
42
               type=unicode),
4330.4.36 by Jonathan Lange
Add a mirror_root parameter the rest of the way up the stack.
43
        Option('mirror-directory',
44
               help='serve branches from this directory. Defaults to '
7732.1.3 by Jonathan Lange
Get rid of the branchesdest config variable.
45
                    'config.codehosting.mirrored_branches_root.'),
6789.11.7 by Michael Hudson
use the internal xml-rpc server for branchfs operations too.
46
        Option('branchfs-endpoint',
4277.4.12 by Jonathan Lange
Shift Launchpad server plugin around. Still no tests :(
47
               help='the url of the internal XML-RPC server. Defaults to '
6789.11.7 by Michael Hudson
use the internal xml-rpc server for branchfs operations too.
48
                    'config.codehosting.branchfs_endpoint.',
4277.4.12 by Jonathan Lange
Shift Launchpad server plugin around. Still no tests :(
49
               type=unicode),
4277.4.7 by Jonathan Lange
Add a sucky implementation of launchpad serving command.
50
        ]
51
4277.4.12 by Jonathan Lange
Shift Launchpad server plugin around. Still no tests :(
52
    takes_args = ['user_id']
4277.4.7 by Jonathan Lange
Add a sucky implementation of launchpad serving command.
53
4277.4.12 by Jonathan Lange
Shift Launchpad server plugin around. Still no tests :(
54
    def get_smart_server(self, transport, port, inet):
4277.4.39 by Jonathan Lange
Docstrings.
55
        """Construct a smart server."""
4277.4.12 by Jonathan Lange
Shift Launchpad server plugin around. Still no tests :(
56
        if inet:
57
            smart_server = medium.SmartServerPipeStreamMedium(
58
                sys.stdin, sys.stdout, transport)
4277.4.7 by Jonathan Lange
Add a sucky implementation of launchpad serving command.
59
        else:
8496.2.1 by Jonathan Lange
BZR_DEFAULT_* lives in medium, not transport.remote.
60
            host = medium.BZR_DEFAULT_INTERFACE
4277.4.12 by Jonathan Lange
Shift Launchpad server plugin around. Still no tests :(
61
            if port is None:
8496.2.1 by Jonathan Lange
BZR_DEFAULT_* lives in medium, not transport.remote.
62
                port = medium.BZR_DEFAULT_PORT
4277.4.12 by Jonathan Lange
Shift Launchpad server plugin around. Still no tests :(
63
            else:
64
                if ':' in port:
65
                    host, port = port.split(':')
66
                port = int(port)
67
            smart_server = server.SmartTCPServer(
68
                transport, host=host, port=port)
69
            print 'listening on port: ', smart_server.port
70
            sys.stdout.flush()
71
        return smart_server
72
73
    def run_server(self, smart_server):
4277.4.39 by Jonathan Lange
Docstrings.
74
        """Run the given smart server."""
4277.4.7 by Jonathan Lange
Add a sucky implementation of launchpad serving command.
75
        # for the duration of this server, no UI output is permitted.
76
        # note that this may cause problems with blackbox tests. This should
5520.1.4 by Aaron Bentley
Cleanup
77
        # be changed with care though, as we dont want to use bandwidth
78
        # sending progress over stderr to smart server clients!
4277.4.7 by Jonathan Lange
Add a sucky implementation of launchpad serving command.
79
        old_factory = ui.ui_factory
80
        try:
81
            ui.ui_factory = ui.SilentUIFactory()
82
            smart_server.serve()
83
        finally:
84
            ui.ui_factory = old_factory
85
4330.4.36 by Jonathan Lange
Add a mirror_root parameter the rest of the way up the stack.
86
    def run(self, user_id, port=None, upload_directory=None,
6789.11.7 by Michael Hudson
use the internal xml-rpc server for branchfs operations too.
87
            mirror_directory=None, branchfs_endpoint_url=None, inet=False):
8426.6.1 by Michael Hudson
bzr ls --versioned --recursive --kind=file | xargs sed -i -e 's,from canonical.codehosting,from lp.codehosting,'
88
        from lp.codehosting.vfs import get_lp_server
7167.9.14 by Michael Hudson
dear holy crap, an acceptance test for bug #297205!
89
        lp_server = get_lp_server(
7675.122.9 by Tim Penhey
Reorder the args for get_lp_server, and use sensible defaults.
90
            int(user_id), branchfs_endpoint_url,
91
            upload_directory, mirror_directory)
4292.1.70 by Jonathan Lange
Simplistic support for marking branches as needing a mirror if they've been
92
        lp_server.setUp()
4292.1.72 by Jonathan Lange
Do our best to clean up everything when we get SIGHUPd
93
6266.3.1 by Jonathan Lange
Fix up locking on the smartserver.
94
        old_lockdir_timeout = lockdir._DEFAULT_TIMEOUT_SECONDS
4292.1.70 by Jonathan Lange
Simplistic support for marking branches as needing a mirror if they've been
95
        try:
4816.1.4 by Jonathan Lange
Logging for the smart server transport. Not everything yet, but most things.
96
            lp_transport = get_transport(lp_server.get_url())
97
            smart_server = self.get_smart_server(lp_transport, port, inet)
6266.3.1 by Jonathan Lange
Fix up locking on the smartserver.
98
            lockdir._DEFAULT_TIMEOUT_SECONDS = 0
4292.1.70 by Jonathan Lange
Simplistic support for marking branches as needing a mirror if they've been
99
            self.run_server(smart_server)
100
        finally:
6266.3.1 by Jonathan Lange
Fix up locking on the smartserver.
101
            lockdir._DEFAULT_TIMEOUT_SECONDS = old_lockdir_timeout
4292.1.70 by Jonathan Lange
Simplistic support for marking branches as needing a mirror if they've been
102
            lp_server.tearDown()
4277.4.12 by Jonathan Lange
Shift Launchpad server plugin around. Still no tests :(
103
104
105
register_command(cmd_launchpad_server)