~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/hooks.py

(gz) Remove bzrlib/util/elementtree/ package (Martin Packman)

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,
30
31
    errors,
31
32
    pyutils,
32
33
    )
 
34
from bzrlib.i18n import gettext
33
35
""")
34
36
 
35
37
 
70
72
 
71
73
_builtin_known_hooks = (
72
74
    ('bzrlib.branch', 'Branch.hooks', 'BranchHooks'),
73
 
    ('bzrlib.bzrdir', 'BzrDir.hooks', 'BzrDirHooks'),
 
75
    ('bzrlib.controldir', 'ControlDir.hooks', 'ControlDirHooks'),
74
76
    ('bzrlib.commands', 'Command.hooks', 'CommandHooks'),
 
77
    ('bzrlib.config', 'ConfigHooks', '_ConfigHooks'),
75
78
    ('bzrlib.info', 'hooks', 'InfoHooks'),
76
79
    ('bzrlib.lock', 'Lock.hooks', 'LockHooks'),
77
80
    ('bzrlib.merge', 'Merger.hooks', 'MergeHooks'),
80
83
    ('bzrlib.smart.client', '_SmartClient.hooks', 'SmartClientHooks'),
81
84
    ('bzrlib.smart.server', 'SmartTCPServer.hooks', 'SmartServerHooks'),
82
85
    ('bzrlib.status', 'hooks', 'StatusHooks'),
 
86
    ('bzrlib.transport', 'Transport.hooks', 'TransportHooks'),
83
87
    ('bzrlib.version_info_formats.format_rio', 'RioVersionInfoBuilder.hooks',
84
88
        'RioVersionInfoBuilderHooks'),
85
89
    ('bzrlib.merge_directive', 'BaseMergeDirective.hooks',
125
129
        """
126
130
        dict.__init__(self)
127
131
        self._callable_names = {}
 
132
        self._lazy_callable_names = {}
128
133
        self._module = module
129
134
        self._member_name = member_name
130
135
 
194
199
        the code names are rarely meaningful for end users and this is not
195
200
        intended for debugging.
196
201
        """
197
 
        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
 
198
211
 
199
212
    def install_named_hook_lazy(self, hook_name, callable_module,
200
213
        callable_member, name):
219
232
                self)
220
233
        else:
221
234
            hook_lazy(callable_module, callable_member, name)
 
235
        if name is not None:
 
236
            self.name_hook_lazy(callable_module, callable_member, name)
222
237
 
223
238
    def install_named_hook(self, hook_name, a_callable, name):
224
239
        """Install a_callable in to the hook hook_name, and label it name.
256
271
        try:
257
272
            uninstall = getattr(hook, "uninstall")
258
273
        except AttributeError:
259
 
            raise errors.UnsupportedOperation(self.install_named_hook_lazy,
260
 
                self)
 
274
            raise errors.UnsupportedOperation(self.uninstall_named_hook, self)
261
275
        else:
262
276
            uninstall(label)
263
277
 
265
279
        """Associate name with a_callable to show users what is running."""
266
280
        self._callable_names[a_callable] = name
267
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
 
268
286
 
269
287
class HookPoint(object):
270
288
    """A single hook that clients can register to be called back when it fires.
310
328
            introduced_string = _format_version_tuple(self.introduced)
311
329
        else:
312
330
            introduced_string = 'unknown'
313
 
        strings.append('Introduced in: %s' % introduced_string)
 
331
        strings.append(gettext('Introduced in: %s') % introduced_string)
314
332
        if self.deprecated:
315
333
            deprecated_string = _format_version_tuple(self.deprecated)
316
 
            strings.append('Deprecated in: %s' % deprecated_string)
 
334
            strings.append(gettext('Deprecated in: %s') % deprecated_string)
317
335
        strings.append('')
318
336
        strings.extend(textwrap.wrap(self.__doc__,
319
337
            break_long_words=False))