~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/server.py

  • Committer: Vincent Ladeuil
  • Date: 2011-07-06 09:22:00 UTC
  • mfrom: (6008 +trunk)
  • mto: (6012.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 6013.
  • Revision ID: v.ladeuil+lp@free.fr-20110706092200-7iai2mwzc0sqdsvf
MergingĀ inĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2011 Canonical Ltd
2
2
#
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
18
18
 
19
19
import errno
20
20
import os.path
21
 
import select
22
21
import socket
23
22
import sys
24
23
import threading
25
24
 
26
 
from bzrlib.hooks import HookPoint, Hooks
 
25
from bzrlib.hooks import Hooks
27
26
from bzrlib import (
28
27
    errors,
29
28
    trace,
104
103
        # The URL that a commit done on the same machine as the server will
105
104
        # have within the servers space. (e.g. file:///home/user/source)
106
105
        # The URL that will be given to other hooks in the same process -
107
 
        # the URL of the backing transport itself. (e.g. chroot+:///)
 
106
        # the URL of the backing transport itself. (e.g. filtered-36195:///)
108
107
        # We need all three because:
109
108
        #  * other machines see the first
110
109
        #  * local commits on this machine should be able to be mapped to
177
176
 
178
177
    def get_url(self):
179
178
        """Return the url of the server"""
180
 
        return "bzr://%s:%d/" % self._sockname
 
179
        return "bzr://%s:%s/" % (self._sockname[0], self._sockname[1])
181
180
 
182
181
    def serve_conn(self, conn, thread_name_suffix):
183
182
        # For WIN32, where the timeout value from the listening socket
240
239
        These are all empty initially, because by default nothing should get
241
240
        notified.
242
241
        """
243
 
        Hooks.__init__(self)
244
 
        self.create_hook(HookPoint('server_started',
 
242
        Hooks.__init__(self, "bzrlib.smart.server", "SmartTCPServer.hooks")
 
243
        self.add_hook('server_started',
245
244
            "Called by the bzr server when it starts serving a directory. "
246
245
            "server_started is called with (backing urls, public url), "
247
246
            "where backing_url is a list of URLs giving the "
248
247
            "server-specific directory locations, and public_url is the "
249
 
            "public URL for the directory being served.", (0, 16), None))
250
 
        self.create_hook(HookPoint('server_started_ex',
 
248
            "public URL for the directory being served.", (0, 16))
 
249
        self.add_hook('server_started_ex',
251
250
            "Called by the bzr server when it starts serving a directory. "
252
251
            "server_started is called with (backing_urls, server_obj).",
253
 
            (1, 17), None))
254
 
        self.create_hook(HookPoint('server_stopped',
 
252
            (1, 17))
 
253
        self.add_hook('server_stopped',
255
254
            "Called by the bzr server when it stops serving a directory. "
256
255
            "server_stopped is called with the same parameters as the "
257
 
            "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))
258
262
 
259
263
SmartTCPServer.hooks = SmartServerHooks()
260
264
 
374
378
        for cleanup in reversed(self.cleanups):
375
379
            cleanup()
376
380
 
377
 
 
378
381
def serve_bzr(transport, host=None, port=None, inet=False):
379
382
    """This is the default implementation of 'bzr serve'.
380
383
    
386
389
    try:
387
390
        bzr_server.set_up(transport, host, port, inet)
388
391
        bzr_server.smart_server.serve()
 
392
    except:
 
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:
 
397
            raise
389
398
    finally:
390
399
        bzr_server.tear_down()
391