18
18
"""Support for plugin hooking logic."""
19
from bzrlib.lazy_import import lazy_import
19
20
from bzrlib import registry
20
from bzrlib.lazy_import import lazy_import
21
from bzrlib.symbol_versioning import deprecated_method, one_five
21
22
lazy_import(globals(), """
32
33
known_hooks = registry.Registry()
33
# known_hooks registry contains
34
# tuple of (module, member name) which is the hook point
35
# module where the specific hooks are defined
36
# callable to get the empty specific Hooks for that attribute
37
34
known_hooks.register_lazy(('bzrlib.branch', 'Branch.hooks'), 'bzrlib.branch',
39
36
known_hooks.register_lazy(('bzrlib.bzrdir', 'BzrDir.hooks'), 'bzrlib.bzrdir',
41
38
known_hooks.register_lazy(('bzrlib.commands', 'Command.hooks'),
42
39
'bzrlib.commands', 'CommandHooks')
43
known_hooks.register_lazy(('bzrlib.info', 'hooks'),
44
'bzrlib.info', 'InfoHooks')
45
40
known_hooks.register_lazy(('bzrlib.lock', 'Lock.hooks'), 'bzrlib.lock',
47
known_hooks.register_lazy(('bzrlib.merge', 'Merger.hooks'), 'bzrlib.merge',
49
known_hooks.register_lazy(('bzrlib.msgeditor', 'hooks'), 'bzrlib.msgeditor',
51
42
known_hooks.register_lazy(('bzrlib.mutabletree', 'MutableTree.hooks'),
52
43
'bzrlib.mutabletree', 'MutableTreeHooks')
53
44
known_hooks.register_lazy(('bzrlib.smart.client', '_SmartClient.hooks'),
54
45
'bzrlib.smart.client', 'SmartClientHooks')
55
46
known_hooks.register_lazy(('bzrlib.smart.server', 'SmartTCPServer.hooks'),
56
47
'bzrlib.smart.server', 'SmartServerHooks')
57
known_hooks.register_lazy(
58
('bzrlib.version_info_formats.format_rio', 'RioVersionInfoBuilder.hooks'),
59
'bzrlib.version_info_formats.format_rio', 'RioVersionInfoBuilderHooks')
60
known_hooks.register_lazy(
61
('bzrlib.merge_directive', 'BaseMergeDirective.hooks'),
62
'bzrlib.merge_directive', 'MergeDirectiveHooks')
65
50
def known_hooks_key_to_object((module_name, member_name)):
148
133
return self._callable_names.get(a_callable, "No hook name")
135
@deprecated_method(one_five)
136
def install_hook(self, hook_name, a_callable):
137
"""Install a_callable in to the hook hook_name.
139
:param hook_name: A hook name. See the __init__ method of BranchHooks
140
for the complete list of hooks.
141
:param a_callable: The callable to be invoked when the hook triggers.
142
The exact signature will depend on the hook - see the __init__
143
method of BranchHooks for details on each hook.
145
self.install_named_hook(hook_name, a_callable, None)
150
147
def install_named_hook(self, hook_name, a_callable, name):
151
148
"""Install a_callable in to the hook hook_name, and label it name.
182
179
:ivar introduced: A version tuple specifying what version the hook was
183
180
introduced in. None indicates an unknown version.
184
181
:ivar deprecated: A version tuple specifying what version the hook was
185
deprecated or superseded in. None indicates that the hook is not
186
superseded or deprecated. If the hook is superseded then the doc
182
deprecated or superceded in. None indicates that the hook is not
183
superceded or deprecated. If the hook is superceded then the doc
187
184
should describe the recommended replacement hook to register for.
188
185
:ivar doc: The docs for using the hook.
220
217
strings.append('Introduced in: %s' % introduced_string)
221
218
if self.deprecated:
222
219
deprecated_string = _format_version_tuple(self.deprecated)
223
strings.append('Deprecated in: %s' % deprecated_string)
221
deprecated_string = 'Not deprecated'
222
strings.append('Deprecated in: %s' % deprecated_string)
224
223
strings.append('')
225
strings.extend(textwrap.wrap(self.__doc__,
226
break_long_words=False))
224
strings.extend(textwrap.wrap(self.__doc__))
227
225
strings.append('')
228
226
return '\n'.join(strings)
279
277
See `Using hooks`_ in the User Guide for examples.
281
.. _Using hooks: ../user-guide/hooks.html
279
.. _Using hooks: ../user-guide/index.html#using-hooks
283
281
The class that contains each hook is given before the hooks it supplies. For
284
282
instance, BranchHooks as the class is the hooks class for