5479
5479
help="Protocol to serve.",
5480
5480
lazy_registry=('bzrlib.transport', 'transport_server_registry'),
5481
5481
value_switches=True),
5483
help='Listen for connections on nominated address.', type=str),
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.',
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
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).'),
5503
def get_host_and_port(self, port):
5504
"""Return the host and port to run the smart server on.
5506
If 'port' is None, None will be returned for the host and port.
5508
If 'port' has a colon in it, the string before the colon will be
5509
interpreted as the host.
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.
5516
if port is not None:
5518
host, port = port.split(':')
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)
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.