/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: Robert Collins
  • Date: 2010-05-06 11:08:10 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506110810-h3j07fh5gmw54s25
Cleaner matcher matching revised unlocking protocol.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007, 2008 Canonical Ltd
 
1
# Copyright (C) 2007-2010 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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
18
18
"""Support for plugin hooking logic."""
 
19
from bzrlib import registry
19
20
from bzrlib.lazy_import import lazy_import
20
 
from bzrlib import registry
21
 
from bzrlib.symbol_versioning import deprecated_method, one_five
22
21
lazy_import(globals(), """
23
22
import textwrap
24
23
 
31
30
 
32
31
 
33
32
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
34
37
known_hooks.register_lazy(('bzrlib.branch', 'Branch.hooks'), 'bzrlib.branch',
35
38
    'BranchHooks')
 
39
known_hooks.register_lazy(('bzrlib.bzrdir', 'BzrDir.hooks'), 'bzrlib.bzrdir',
 
40
    'BzrDirHooks')
36
41
known_hooks.register_lazy(('bzrlib.commands', 'Command.hooks'),
37
42
    'bzrlib.commands', 'CommandHooks')
 
43
known_hooks.register_lazy(('bzrlib.info', 'hooks'),
 
44
    'bzrlib.info', 'InfoHooks')
38
45
known_hooks.register_lazy(('bzrlib.lock', 'Lock.hooks'), 'bzrlib.lock',
39
46
    'LockHooks')
 
47
known_hooks.register_lazy(('bzrlib.merge', 'Merger.hooks'), 'bzrlib.merge',
 
48
    'MergeHooks')
 
49
known_hooks.register_lazy(('bzrlib.msgeditor', 'hooks'), 'bzrlib.msgeditor',
 
50
    'MessageEditorHooks')
40
51
known_hooks.register_lazy(('bzrlib.mutabletree', 'MutableTree.hooks'),
41
52
    'bzrlib.mutabletree', 'MutableTreeHooks')
42
53
known_hooks.register_lazy(('bzrlib.smart.client', '_SmartClient.hooks'),
43
54
    'bzrlib.smart.client', 'SmartClientHooks')
44
55
known_hooks.register_lazy(('bzrlib.smart.server', 'SmartTCPServer.hooks'),
45
56
    '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')
46
63
 
47
64
 
48
65
def known_hooks_key_to_object((module_name, member_name)):
130
147
        """
131
148
        return self._callable_names.get(a_callable, "No hook name")
132
149
 
133
 
    @deprecated_method(one_five)
134
 
    def install_hook(self, hook_name, a_callable):
135
 
        """Install a_callable in to the hook hook_name.
136
 
 
137
 
        :param hook_name: A hook name. See the __init__ method of BranchHooks
138
 
            for the complete list of hooks.
139
 
        :param a_callable: The callable to be invoked when the hook triggers.
140
 
            The exact signature will depend on the hook - see the __init__
141
 
            method of BranchHooks for details on each hook.
142
 
        """
143
 
        self.install_named_hook(hook_name, a_callable, None)
144
 
 
145
150
    def install_named_hook(self, hook_name, a_callable, name):
146
151
        """Install a_callable in to the hook hook_name, and label it name.
147
152
 
177
182
    :ivar introduced: A version tuple specifying what version the hook was
178
183
        introduced in. None indicates an unknown version.
179
184
    :ivar deprecated: A version tuple specifying what version the hook was
180
 
        deprecated or superceded in. None indicates that the hook is not
181
 
        superceded or deprecated. If the hook is superceded then the doc
 
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
187
        should describe the recommended replacement hook to register for.
183
188
    :ivar doc: The docs for using the hook.
184
189
    """
215
220
        strings.append('Introduced in: %s' % introduced_string)
216
221
        if self.deprecated:
217
222
            deprecated_string = _format_version_tuple(self.deprecated)
218
 
        else:
219
 
            deprecated_string = 'Not deprecated'
220
 
        strings.append('Deprecated in: %s' % deprecated_string)
 
223
            strings.append('Deprecated in: %s' % deprecated_string)
221
224
        strings.append('')
222
 
        strings.extend(textwrap.wrap(self.__doc__))
 
225
        strings.extend(textwrap.wrap(self.__doc__,
 
226
            break_long_words=False))
223
227
        strings.append('')
224
228
        return '\n'.join(strings)
225
229
 
274
278
 
275
279
See `Using hooks`_ in the User Guide for examples.
276
280
 
277
 
.. _Using hooks: ../user-guide/index.html#using-hooks
 
281
.. _Using hooks: ../user-guide/hooks.html
278
282
 
279
283
The class that contains each hook is given before the hooks it supplies. For
280
284
instance, BranchHooks as the class is the hooks class for