/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/hooks.py

  • Committer: Jelmer Vernooij
  • Date: 2012-01-30 14:12:36 UTC
  • mfrom: (6437.3.28 2.5)
  • mto: This revision was merged to the branch mainline in revision 6522.
  • Revision ID: jelmer@samba.org-20120130141236-66k8qj1he6q2nq3r
Merge 2.5 branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
 
18
17
"""Support for plugin hooking logic."""
19
18
 
 
19
from __future__ import absolute_import
 
20
 
20
21
from bzrlib import (
21
22
    registry,
22
23
    symbol_versioning,
71
72
 
72
73
_builtin_known_hooks = (
73
74
    ('bzrlib.branch', 'Branch.hooks', 'BranchHooks'),
74
 
    ('bzrlib.bzrdir', 'BzrDir.hooks', 'BzrDirHooks'),
 
75
    ('bzrlib.controldir', 'ControlDir.hooks', 'ControlDirHooks'),
75
76
    ('bzrlib.commands', 'Command.hooks', 'CommandHooks'),
76
77
    ('bzrlib.config', 'ConfigHooks', '_ConfigHooks'),
77
78
    ('bzrlib.info', 'hooks', 'InfoHooks'),
82
83
    ('bzrlib.smart.client', '_SmartClient.hooks', 'SmartClientHooks'),
83
84
    ('bzrlib.smart.server', 'SmartTCPServer.hooks', 'SmartServerHooks'),
84
85
    ('bzrlib.status', 'hooks', 'StatusHooks'),
 
86
    ('bzrlib.transport', 'Transport.hooks', 'TransportHooks'),
85
87
    ('bzrlib.version_info_formats.format_rio', 'RioVersionInfoBuilder.hooks',
86
88
        'RioVersionInfoBuilderHooks'),
87
89
    ('bzrlib.merge_directive', 'BaseMergeDirective.hooks',
127
129
        """
128
130
        dict.__init__(self)
129
131
        self._callable_names = {}
 
132
        self._lazy_callable_names = {}
130
133
        self._module = module
131
134
        self._member_name = member_name
132
135
 
196
199
        the code names are rarely meaningful for end users and this is not
197
200
        intended for debugging.
198
201
        """
199
 
        return self._callable_names.get(a_callable, "No hook name")
 
202
        name = self._callable_names.get(a_callable, None)
 
203
        if name is None and a_callable is not None:
 
204
            name = self._lazy_callable_names.get((a_callable.__module__,
 
205
                                                  a_callable.__name__),
 
206
                                                 None)
 
207
        if name is None:
 
208
            return 'No hook name'
 
209
        return name
 
210
 
200
211
 
201
212
    def install_named_hook_lazy(self, hook_name, callable_module,
202
213
        callable_member, name):
221
232
                self)
222
233
        else:
223
234
            hook_lazy(callable_module, callable_member, name)
 
235
        if name is not None:
 
236
            self.name_hook_lazy(callable_module, callable_member, name)
224
237
 
225
238
    def install_named_hook(self, hook_name, a_callable, name):
226
239
        """Install a_callable in to the hook hook_name, and label it name.
266
279
        """Associate name with a_callable to show users what is running."""
267
280
        self._callable_names[a_callable] = name
268
281
 
 
282
    def name_hook_lazy(self, callable_module, callable_member, callable_name):
 
283
        self._lazy_callable_names[(callable_module, callable_member)]= \
 
284
            callable_name
 
285
 
269
286
 
270
287
class HookPoint(object):
271
288
    """A single hook that clients can register to be called back when it fires.