1
# Copyright (C) 2004, 2005, 2006, 2007, 2008 Canonical Ltd
1
# Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
4083
def run(self, port=None, inet=False, directory=None, allow_writes=False):
4083
def run_smart_server(self, smart_server):
4084
"""Run 'smart_server' forever, with no UI output at all."""
4085
# For the duration of this server, no UI output is permitted. note
4086
# that this may cause problems with blackbox tests. This should be
4087
# changed with care though, as we dont want to use bandwidth sending
4088
# progress over stderr to smart server clients!
4084
4089
from bzrlib import lockdir
4090
old_factory = ui.ui_factory
4091
old_lockdir_timeout = lockdir._DEFAULT_TIMEOUT_SECONDS
4093
ui.ui_factory = ui.SilentUIFactory()
4094
lockdir._DEFAULT_TIMEOUT_SECONDS = 0
4095
smart_server.serve()
4097
ui.ui_factory = old_factory
4098
lockdir._DEFAULT_TIMEOUT_SECONDS = old_lockdir_timeout
4100
def get_host_and_port(self, port):
4101
"""Return the host and port to run the smart server on.
4103
If 'port' is None, the default host (`medium.BZR_DEFAULT_INTERFACE`)
4104
and port (`medium.BZR_DEFAULT_PORT`) will be used.
4106
If 'port' has a colon in it, the string before the colon will be
4107
interpreted as the host.
4109
:param port: A string of the port to run the server on.
4110
:return: A tuple of (host, port), where 'host' is a host name or IP,
4111
and port is an integer TCP/IP port.
4113
from bzrlib.smart import medium
4114
host = medium.BZR_DEFAULT_INTERFACE
4116
port = medium.BZR_DEFAULT_PORT
4119
host, port = port.split(':')
4123
def get_smart_server(self, transport, inet, port):
4124
"""Construct a smart server.
4126
:param transport: The base transport from which branches will be
4128
:param inet: If True, serve over stdin and stdout. Used for running
4130
:param port: The port to listen on. By default, it's `
4131
medium.BZR_DEFAULT_PORT`. See `get_host_and_port` for more
4133
:return: A smart server.
4085
4135
from bzrlib.smart import medium, server
4137
smart_server = medium.SmartServerPipeStreamMedium(
4138
sys.stdin, sys.stdout, transport)
4140
host, port = self.get_host_and_port(port)
4141
smart_server = server.SmartTCPServer(
4142
transport, host=host, port=port)
4143
note('listening on port: %s' % smart_server.port)
4146
def run(self, port=None, inet=False, directory=None, allow_writes=False):
4086
4147
from bzrlib.transport import get_transport
4087
4148
from bzrlib.transport.chroot import ChrootServer
4088
4149
if directory is None:
4093
4154
chroot_server = ChrootServer(get_transport(url))
4094
4155
chroot_server.setUp()
4095
4156
t = get_transport(chroot_server.get_url())
4097
smart_server = medium.SmartServerPipeStreamMedium(
4098
sys.stdin, sys.stdout, t)
4100
host = medium.BZR_DEFAULT_INTERFACE
4102
port = medium.BZR_DEFAULT_PORT
4105
host, port = port.split(':')
4107
smart_server = server.SmartTCPServer(t, host=host, port=port)
4108
print 'listening on port: ', smart_server.port
4110
# for the duration of this server, no UI output is permitted.
4111
# note that this may cause problems with blackbox tests. This should
4112
# be changed with care though, as we dont want to use bandwidth sending
4113
# progress over stderr to smart server clients!
4114
old_factory = ui.ui_factory
4115
old_lockdir_timeout = lockdir._DEFAULT_TIMEOUT_SECONDS
4117
ui.ui_factory = ui.SilentUIFactory()
4118
lockdir._DEFAULT_TIMEOUT_SECONDS = 0
4119
smart_server.serve()
4121
ui.ui_factory = old_factory
4122
lockdir._DEFAULT_TIMEOUT_SECONDS = old_lockdir_timeout
4157
smart_server = self.get_smart_server(t, inet, port)
4158
self.run_smart_server(smart_server)
4125
4161
class cmd_join(Command):