~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Patch Queue Manager
  • Date: 2012-03-04 18:47:59 UTC
  • mfrom: (6475.2.3 544054-serve-port)
  • Revision ID: pqm@pqm.ubuntu.com-20120304184759-kpae3rpzzscn4vjm
(jelmer) Split the --port option into --listen and --port. (Ross Lagerwall)

Show diffs side-by-side

added added

removed removed

Lines of Context:
5479
5479
               help="Protocol to serve.",
5480
5480
               lazy_registry=('bzrlib.transport', 'transport_server_registry'),
5481
5481
               value_switches=True),
 
5482
        Option('listen',
 
5483
               help='Listen for connections on nominated address.', type=str),
5482
5484
        Option('port',
5483
 
               help='Listen for connections on nominated port of the form '
5484
 
                    '[hostname:]portnumber.  Passing 0 as the port number will '
5485
 
                    'result in a dynamically allocated port.  The default port '
5486
 
                    'depends on the protocol.',
5487
 
               type=str),
 
5485
               help='Listen for connections on nominated port.  Passing 0 as '
 
5486
                    'the port number will result in a dynamically allocated '
 
5487
                    'port.  The default port depends on the protocol.',
 
5488
               type=int),
5488
5489
        custom_help('directory',
5489
5490
               help='Serve contents of this directory.'),
5490
5491
        Option('allow-writes',
5500
5501
               help='Override the default idle client timeout (5min).'),
5501
5502
        ]
5502
5503
 
5503
 
    def get_host_and_port(self, port):
5504
 
        """Return the host and port to run the smart server on.
5505
 
 
5506
 
        If 'port' is None, None will be returned for the host and port.
5507
 
 
5508
 
        If 'port' has a colon in it, the string before the colon will be
5509
 
        interpreted as the host.
5510
 
 
5511
 
        :param port: A string of the port to run the server on.
5512
 
        :return: A tuple of (host, port), where 'host' is a host name or IP,
5513
 
            and port is an integer TCP/IP port.
5514
 
        """
5515
 
        host = None
5516
 
        if port is not None:
5517
 
            if ':' in port:
5518
 
                host, port = port.split(':')
5519
 
            port = int(port)
5520
 
        return host, port
5521
 
 
5522
 
    def run(self, port=None, inet=False, directory=None, allow_writes=False,
5523
 
            protocol=None, client_timeout=None):
 
5504
    def run(self, listen=None, port=None, inet=False, directory=None,
 
5505
            allow_writes=False, protocol=None, client_timeout=None):
5524
5506
        from bzrlib import transport
5525
5507
        if directory is None:
5526
5508
            directory = os.getcwd()
5527
5509
        if protocol is None:
5528
5510
            protocol = transport.transport_server_registry.get()
5529
 
        host, port = self.get_host_and_port(port)
5530
5511
        url = transport.location_to_url(directory)
5531
5512
        if not allow_writes:
5532
5513
            url = 'readonly+' + url
5533
5514
        t = transport.get_transport_from_url(url)
5534
5515
        try:
5535
 
            protocol(t, host, port, inet, client_timeout)
 
5516
            protocol(t, listen, port, inet, client_timeout)
5536
5517
        except TypeError, e:
5537
5518
            # We use symbol_versioning.deprecated_in just so that people
5538
5519
            # grepping can find it here.