~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Jelmer Vernooij
  • Date: 2009-05-28 16:14:16 UTC
  • mfrom: (4387 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4389.
  • Revision ID: jelmer@samba.org-20090528161416-k7x0l8hwuk2kyvsf
merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4540
4540
    takes_options = [
4541
4541
        Option('inet',
4542
4542
               help='Serve on stdin/out for use from inetd or sshd.'),
 
4543
        RegistryOption('protocol', 
 
4544
               help="Protocol to serve.", 
 
4545
               lazy_registry=('bzrlib.transport', 'transport_server_registry'),
 
4546
               value_switches=True),
4543
4547
        Option('port',
4544
4548
               help='Listen for connections on nominated port of the form '
4545
4549
                    '[hostname:]portnumber.  Passing 0 as the port number will '
4546
 
                    'result in a dynamically allocated port.  The default port is '
4547
 
                    '4155.',
 
4550
                    'result in a dynamically allocated port.  The default port '
 
4551
                    'depends on the protocol.',
4548
4552
               type=str),
4549
4553
        Option('directory',
4550
4554
               help='Serve contents of this directory.',
4556
4560
                ),
4557
4561
        ]
4558
4562
 
4559
 
    def run_smart_server(self, smart_server):
4560
 
        """Run 'smart_server' forever, with no UI output at all."""
4561
 
        # For the duration of this server, no UI output is permitted. note
4562
 
        # that this may cause problems with blackbox tests. This should be
4563
 
        # changed with care though, as we dont want to use bandwidth sending
4564
 
        # progress over stderr to smart server clients!
4565
 
        from bzrlib import lockdir
4566
 
        old_factory = ui.ui_factory
4567
 
        old_lockdir_timeout = lockdir._DEFAULT_TIMEOUT_SECONDS
4568
 
        try:
4569
 
            ui.ui_factory = ui.SilentUIFactory()
4570
 
            lockdir._DEFAULT_TIMEOUT_SECONDS = 0
4571
 
            smart_server.serve()
4572
 
        finally:
4573
 
            ui.ui_factory = old_factory
4574
 
            lockdir._DEFAULT_TIMEOUT_SECONDS = old_lockdir_timeout
4575
 
 
4576
4563
    def get_host_and_port(self, port):
4577
4564
        """Return the host and port to run the smart server on.
4578
4565
 
4579
 
        If 'port' is None, the default host (`medium.BZR_DEFAULT_INTERFACE`)
4580
 
        and port (`medium.BZR_DEFAULT_PORT`) will be used.
 
4566
        If 'port' is None, None will be returned for the host and port.
4581
4567
 
4582
4568
        If 'port' has a colon in it, the string before the colon will be
4583
4569
        interpreted as the host.
4586
4572
        :return: A tuple of (host, port), where 'host' is a host name or IP,
4587
4573
            and port is an integer TCP/IP port.
4588
4574
        """
4589
 
        from bzrlib.smart import medium
4590
 
        host = medium.BZR_DEFAULT_INTERFACE
4591
 
        if port is None:
4592
 
            port = medium.BZR_DEFAULT_PORT
4593
 
        else:
 
4575
        host = None
 
4576
        if port is not None:
4594
4577
            if ':' in port:
4595
4578
                host, port = port.split(':')
4596
4579
            port = int(port)
4597
4580
        return host, port
4598
4581
 
4599
 
    def get_smart_server(self, transport, inet, port):
4600
 
        """Construct a smart server.
4601
 
 
4602
 
        :param transport: The base transport from which branches will be
4603
 
            served.
4604
 
        :param inet: If True, serve over stdin and stdout. Used for running
4605
 
            from inet.
4606
 
        :param port: The port to listen on. By default, it's `
4607
 
            medium.BZR_DEFAULT_PORT`. See `get_host_and_port` for more
4608
 
            information.
4609
 
        :return: A smart server.
4610
 
        """
4611
 
        from bzrlib.smart import medium, server
4612
 
        if inet:
4613
 
            smart_server = medium.SmartServerPipeStreamMedium(
4614
 
                sys.stdin, sys.stdout, transport)
4615
 
        else:
4616
 
            host, port = self.get_host_and_port(port)
4617
 
            smart_server = server.SmartTCPServer(
4618
 
                transport, host=host, port=port)
4619
 
            note('listening on port: %s' % smart_server.port)
4620
 
        return smart_server
4621
 
 
4622
 
    def run(self, port=None, inet=False, directory=None, allow_writes=False):
4623
 
        from bzrlib.transport import get_transport
4624
 
        from bzrlib.transport.chroot import ChrootServer
 
4582
    def run(self, port=None, inet=False, directory=None, allow_writes=False,
 
4583
            protocol=None):
 
4584
        from bzrlib.transport import get_transport, transport_server_registry
4625
4585
        if directory is None:
4626
4586
            directory = os.getcwd()
 
4587
        if protocol is None:
 
4588
            protocol = transport_server_registry.get()
 
4589
        host, port = self.get_host_and_port(port)
4627
4590
        url = urlutils.local_path_to_url(directory)
4628
4591
        if not allow_writes:
4629
4592
            url = 'readonly+' + url
4630
 
        chroot_server = ChrootServer(get_transport(url))
4631
 
        chroot_server.setUp()
4632
 
        t = get_transport(chroot_server.get_url())
4633
 
        smart_server = self.get_smart_server(t, inet, port)
4634
 
        self.run_smart_server(smart_server)
 
4593
        transport = get_transport(url)
 
4594
        protocol(transport, host, port, inet)
4635
4595
 
4636
4596
 
4637
4597
class cmd_join(Command):
4899
4859
 
4900
4860
 
4901
4861
class cmd_bundle_revisions(Command):
4902
 
 
4903
4862
    """Create a merge-directive for submitting changes.
4904
4863
 
4905
4864
    A merge directive provides many things needed for requesting merges: