/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 breezy/hooks.py

  • Committer: Jelmer Vernooij
  • Date: 2020-05-06 02:13:25 UTC
  • mfrom: (7490.7.21 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200506021325-awbmmqu1zyorz7sj
Merge 3.1 branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Support for plugin hooking logic."""
18
18
 
19
 
from __future__ import absolute_import
20
 
 
21
19
from . import (
22
20
    errors,
23
21
    registry,
51
49
    # callable to get the empty specific Hooks for that attribute
52
50
 
53
51
    def register_lazy_hook(self, hook_module_name, hook_member_name,
54
 
            hook_factory_member_name):
 
52
                           hook_factory_member_name):
55
53
        self.register_lazy((hook_module_name, hook_member_name),
56
 
            hook_module_name, hook_factory_member_name)
 
54
                           hook_module_name, hook_factory_member_name)
57
55
 
58
56
    def iter_parent_objects(self):
59
57
        """Yield (hook_key, (parent_object, attr)) tuples for every registered
164
162
        hook_docs = []
165
163
        name = self.__class__.__name__
166
164
        hook_docs.append(name)
167
 
        hook_docs.append("-"*len(name))
 
165
        hook_docs.append("-" * len(name))
168
166
        hook_docs.append("")
169
167
        for hook_name in hook_names:
170
168
            hook = self[hook_name]
177
175
                strings.append("~" * len(hook_name))
178
176
                strings.append("")
179
177
                strings.append("An old-style hook. For documentation see the __init__ "
180
 
                    "method of '%s'\n" % (name,))
 
178
                               "method of '%s'\n" % (name,))
181
179
                hook_docs.extend(strings)
182
180
        return "\n".join(hook_docs)
183
181
 
198
196
            return 'No hook name'
199
197
        return name
200
198
 
201
 
 
202
199
    def install_named_hook_lazy(self, hook_name, callable_module,
203
 
        callable_member, name):
 
200
                                callable_member, name):
204
201
        """Install a_callable in to the hook hook_name lazily, and label it.
205
202
 
206
203
        :param hook_name: A hook name. See the __init__ method for the complete
219
216
            hook_lazy = getattr(hook, "hook_lazy")
220
217
        except AttributeError:
221
218
            raise errors.UnsupportedOperation(self.install_named_hook_lazy,
222
 
                self)
 
219
                                              self)
223
220
        else:
224
221
            hook_lazy(callable_module, callable_member, name)
225
222
        if name is not None:
270
267
        self._callable_names[a_callable] = name
271
268
 
272
269
    def name_hook_lazy(self, callable_module, callable_member, callable_name):
273
 
        self._lazy_callable_names[(callable_module, callable_member)]= \
 
270
        self._lazy_callable_names[(callable_module, callable_member)] = \
274
271
            callable_name
275
272
 
276
273
 
312
309
        """
313
310
        strings = []
314
311
        strings.append(self.name)
315
 
        strings.append('~'*len(self.name))
 
312
        strings.append('~' * len(self.name))
316
313
        strings.append('')
317
314
        if self.introduced:
318
315
            introduced_string = _format_version_tuple(self.introduced)
324
321
            strings.append(gettext('Deprecated in: %s') % deprecated_string)
325
322
        strings.append('')
326
323
        strings.extend(textwrap.wrap(self.__doc__,
327
 
            break_long_words=False))
 
324
                                     break_long_words=False))
328
325
        strings.append('')
329
326
        return '\n'.join(strings)
330
327
 
341
338
            processing.
342
339
        """
343
340
        obj_getter = registry._LazyObjectGetter(callback_module,
344
 
            callback_member)
 
341
                                                callback_member)
345
342
        self._callbacks.append((obj_getter, callback_label))
346
343
 
347
344
    def hook(self, callback, callback_label):
393
390
 
394
391
 
395
392
_help_prefix = \
396
 
"""
 
393
    """
397
394
Hooks
398
395
=====
399
396
 
425
422
 
426
423
"""
427
424
 
 
425
 
428
426
def hooks_help_text(topic):
429
427
    segments = [_help_prefix]
430
428
    for hook_key in sorted(known_hooks.keys()):
439
437
 
440
438
 
441
439
def install_lazy_named_hook(hookpoints_module, hookpoints_name, hook_name,
442
 
    a_callable, name):
 
440
                            a_callable, name):
443
441
    """Install a callable in to a hook lazily, and label it name.
444
442
 
445
443
    :param hookpoints_module: Module name of the hook points.