26
from bzrlib.hooks import HookPoint, Hooks
25
from bzrlib.hooks import Hooks
27
26
from bzrlib import (
29
transport as _mod_transport,
32
31
from bzrlib.lazy_import import lazy_import
33
32
lazy_import(globals(), """
34
33
from bzrlib.smart import medium
35
34
from bzrlib.transport import (
40
38
from bzrlib import (
105
103
# The URL that a commit done on the same machine as the server will
106
104
# have within the servers space. (e.g. file:///home/user/source)
107
105
# The URL that will be given to other hooks in the same process -
108
# the URL of the backing transport itself. (e.g. chroot+:///)
106
# the URL of the backing transport itself. (e.g. filtered-36195:///)
109
107
# We need all three because:
110
108
# * other machines see the first
111
109
# * local commits on this machine should be able to be mapped to
179
177
def get_url(self):
180
178
"""Return the url of the server"""
181
return "bzr://%s:%d/" % self._sockname
179
return "bzr://%s:%s/" % (self._sockname[0], self._sockname[1])
183
181
def serve_conn(self, conn, thread_name_suffix):
184
182
# For WIN32, where the timeout value from the listening socket
241
239
These are all empty initially, because by default nothing should get
245
self.create_hook(HookPoint('server_started',
242
Hooks.__init__(self, "bzrlib.smart.server", "SmartTCPServer.hooks")
243
self.add_hook('server_started',
246
244
"Called by the bzr server when it starts serving a directory. "
247
245
"server_started is called with (backing urls, public url), "
248
246
"where backing_url is a list of URLs giving the "
249
247
"server-specific directory locations, and public_url is the "
250
"public URL for the directory being served.", (0, 16), None))
251
self.create_hook(HookPoint('server_started_ex',
248
"public URL for the directory being served.", (0, 16))
249
self.add_hook('server_started_ex',
252
250
"Called by the bzr server when it starts serving a directory. "
253
251
"server_started is called with (backing_urls, server_obj).",
255
self.create_hook(HookPoint('server_stopped',
253
self.add_hook('server_stopped',
256
254
"Called by the bzr server when it stops serving a directory. "
257
255
"server_stopped is called with the same parameters as the "
258
"server_started hook: (backing_urls, public_url).", (0, 16), None))
256
"server_started hook: (backing_urls, public_url).", (0, 16))
260
258
SmartTCPServer.hooks = SmartServerHooks()
327
325
chroot_server = chroot.ChrootServer(transport)
328
326
chroot_server.start_server()
329
327
self.cleanups.append(chroot_server.stop_server)
330
transport = get_transport(chroot_server.get_url())
328
transport = _mod_transport.get_transport(chroot_server.get_url())
331
329
if self.base_path is not None:
332
330
# Decorate the server's backing transport with a filter that can
333
331
# expand homedirs.
334
332
expand_userdirs = self._make_expand_userdirs_filter(transport)
335
333
expand_userdirs.start_server()
336
334
self.cleanups.append(expand_userdirs.stop_server)
337
transport = get_transport(expand_userdirs.get_url())
335
transport = _mod_transport.get_transport(expand_userdirs.get_url())
338
336
self.transport = transport
340
338
def _make_smart_server(self, host, port, inet):