/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: 2011-01-20 21:39:26 UTC
  • mto: (5622.2.3 lazy-hooks)
  • mto: This revision was merged to the branch mainline in revision 5668.
  • Revision ID: jelmer@samba.org-20110120213926-wrfgbd0qi242qp98
Remove BranchHooks references.

Show diffs side-by-side

added added

removed removed

Lines of Context:
170
170
        callable_member, name):
171
171
        """Install a_callable in to the hook hook_name lazily, and label it.
172
172
 
173
 
        :param hook_name: A hook name. See the __init__ method of BranchHooks
174
 
            for the complete list of hooks.
 
173
        :param hook_name: A hook name. See the __init__ method for the complete
 
174
            list of hooks.
175
175
        :param callable_module: Name of the module in which the callable is
176
176
            present.
177
177
        :param callable_member: Member name of the callable.
193
193
    def install_named_hook(self, hook_name, a_callable, name):
194
194
        """Install a_callable in to the hook hook_name, and label it name.
195
195
 
196
 
        :param hook_name: A hook name. See the __init__ method of BranchHooks
197
 
            for the complete list of hooks.
 
196
        :param hook_name: A hook name. See the __init__ method for the complete
 
197
            list of hooks.
198
198
        :param a_callable: The callable to be invoked when the hook triggers.
199
199
            The exact signature will depend on the hook - see the __init__
200
 
            method of BranchHooks for details on each hook.
 
200
            method for details on each hook.
201
201
        :param name: A name to associate a_callable with, to show users what is
202
202
            running.
203
203
        """
301
301
        if callback_label is not None:
302
302
            self._callback_names[obj_getter] = callback_label
303
303
 
 
304
    def _get_callbacks(self):
 
305
        
 
306
 
304
307
    def __iter__(self):
305
 
        return (callback.get_obj() for callback in self._callbacks)
 
308
        return (callback.get_obj() for callback in self._get_callbacks())
306
309
 
307
310
    def __len__(self):
308
 
        return len(self._callbacks)
 
311
        return len(self._get_callbacks())
309
312
 
310
313
    def __repr__(self):
311
314
        strings = []
312
315
        strings.append("<%s(" % type(self).__name__)
313
316
        strings.append(self.name)
314
317
        strings.append("), callbacks=[")
315
 
        for callback in self._callbacks:
 
318
        callbacks = self._get_callbacks()
 
319
        for callback in callbacks:
316
320
            strings.append(repr(callback.get_obj()))
317
321
            strings.append("(")
318
322
            strings.append(self._callback_names[callback])
319
323
            strings.append("),")
320
 
        if len(self._callbacks) == 1:
 
324
        if len(callbacks) == 1:
321
325
            strings[-1] = ")"
322
326
        strings.append("]>")
323
327
        return ''.join(strings)
362
366
        hooks = known_hooks_key_to_object(hook_key)
363
367
        segments.append(hooks.docs())
364
368
    return '\n'.join(segments)
 
369
 
 
370
 
 
371
_lazy_hooks = {}
 
372
 
 
373
 
 
374
def install_lazy_named_hook(hookpoints_module, hookpoints_name, hook_name,
 
375
    a_callable, name):
 
376
    """Install a callable in to a hook lazily, and label it name.
 
377
 
 
378
    :param hookpoints_module: Module name of the hook points.
 
379
    :param hookpoints_name: Name of the hook points.
 
380
    :param hook_name: A hook name.
 
381
    :param callable: a callable to call for the hook.
 
382
    :param name: A name to associate a_callable with, to show users what is
 
383
        running.
 
384
    """
 
385
    key = (hookpoints_module, hookpoints_name, hook_name)
 
386
    _lazy_hooks.setdefault(key, []).append((a_callable, name))