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))
257
self.add_hook('server_exception',
258
"Called by the bzr server when an exception occurs. "
259
"server_exception is called with the sys.exc_info() tuple "
260
"return true for the hook if the exception has been handled, "
261
"in which case the server will exit normally.", (2, 4))
260
263
SmartTCPServer.hooks = SmartServerHooks()
327
330
chroot_server = chroot.ChrootServer(transport)
328
331
chroot_server.start_server()
329
332
self.cleanups.append(chroot_server.stop_server)
330
transport = get_transport(chroot_server.get_url())
333
transport = _mod_transport.get_transport(chroot_server.get_url())
331
334
if self.base_path is not None:
332
335
# Decorate the server's backing transport with a filter that can
333
336
# expand homedirs.
334
337
expand_userdirs = self._make_expand_userdirs_filter(transport)
335
338
expand_userdirs.start_server()
336
339
self.cleanups.append(expand_userdirs.stop_server)
337
transport = get_transport(expand_userdirs.get_url())
340
transport = _mod_transport.get_transport(expand_userdirs.get_url())
338
341
self.transport = transport
340
343
def _make_smart_server(self, host, port, inet):
388
390
bzr_server.set_up(transport, host, port, inet)
389
391
bzr_server.smart_server.serve()
393
hook_caught_exception = False
394
for hook in SmartTCPServer.hooks['server_exception']:
395
hook_caught_exception = hook(sys.exc_info())
396
if not hook_caught_exception:
391
399
bzr_server.tear_down()