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