4540
4540
takes_options = [
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),
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 '
4550
'result in a dynamically allocated port. The default port '
4551
'depends on the protocol.',
4549
4553
Option('directory',
4550
4554
help='Serve contents of this directory.',
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
4569
ui.ui_factory = ui.SilentUIFactory()
4570
lockdir._DEFAULT_TIMEOUT_SECONDS = 0
4571
smart_server.serve()
4573
ui.ui_factory = old_factory
4574
lockdir._DEFAULT_TIMEOUT_SECONDS = old_lockdir_timeout
4576
4563
def get_host_and_port(self, port):
4577
4564
"""Return the host and port to run the smart server on.
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.
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.
4589
from bzrlib.smart import medium
4590
host = medium.BZR_DEFAULT_INTERFACE
4592
port = medium.BZR_DEFAULT_PORT
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
4599
def get_smart_server(self, transport, inet, port):
4600
"""Construct a smart server.
4602
:param transport: The base transport from which branches will be
4604
:param inet: If True, serve over stdin and stdout. Used for running
4606
:param port: The port to listen on. By default, it's `
4607
medium.BZR_DEFAULT_PORT`. See `get_host_and_port` for more
4609
:return: A smart server.
4611
from bzrlib.smart import medium, server
4613
smart_server = medium.SmartServerPipeStreamMedium(
4614
sys.stdin, sys.stdout, transport)
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)
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,
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)
4637
4597
class cmd_join(Command):
4892
4852
def run(self, submit_branch=None, public_branch=None, no_bundle=False,
4893
4853
no_patch=False, revision=None, remember=False, output=None,
4894
format='4', mail_to=None, message=None, body=None, **kwargs):
4854
format=None, mail_to=None, message=None, body=None, **kwargs):
4895
4855
return self._run(submit_branch, revision, public_branch, remember,
4896
4856
format, no_bundle, no_patch, output,
4897
4857
kwargs.get('from', '.'), mail_to, message, body)
4936
4896
'changes to submit.', remembered_submit_branch,
4899
if mail_to is None or format is None:
4940
4900
submit_config = Branch.open(submit_branch).get_config()
4941
mail_to = submit_config.get_user_option("child_submit_to")
4902
mail_to = submit_config.get_user_option("child_submit_to")
4904
format = submit_config.get_user_option("child_submit_format")
4943
4906
stored_public_branch = branch.get_public_branch()
4944
4907
if public_branch is None:
4961
4924
revision_id = branch.last_revision()
4962
4925
if revision_id == NULL_REVISION:
4963
4926
raise errors.BzrCommandError('No revisions to submit.')
4964
4929
if format == '4':
4965
4930
directive = merge_directive.MergeDirective2.from_objects(
4966
4931
branch.repository, revision_id, time.time(),
4985
4950
osutils.local_time_offset(), submit_branch,
4986
4951
public_branch=public_branch, patch_type=patch_type,
4987
4952
message=message)
4954
raise errors.BzrCommandError("No such send format '%s'." %
4989
4957
if output is None:
4990
4958
directive.compose_merge_request(mail_client, mail_to, body,
5066
5034
def run(self, submit_branch=None, public_branch=None, no_bundle=False,
5067
5035
no_patch=False, revision=None, remember=False, output=None,
5068
format='4', **kwargs):
5036
format=None, **kwargs):
5069
5037
if output is None:
5071
5039
return self._run(submit_branch, revision, public_branch, remember,