~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/hooks.py

  • Committer: Martin Pool
  • Date: 2008-05-02 02:31:14 UTC
  • mfrom: (3399 +trunk)
  • mto: (3408.1.1 doc)
  • mto: This revision was merged to the branch mainline in revision 3409.
  • Revision ID: mbp@sourcefrog.net-20080502023114-y2gcg3w3jc770j9m
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""Support for plugin hooking logic."""
19
19
from bzrlib.lazy_import import lazy_import
 
20
from bzrlib.symbol_versioning import deprecated_method, one_five
20
21
lazy_import(globals(), """
21
22
from bzrlib import (
22
23
        errors,
45
46
        """
46
47
        return self._callable_names.get(a_callable, "No hook name")
47
48
 
 
49
    @deprecated_method(one_five)
48
50
    def install_hook(self, hook_name, a_callable):
49
51
        """Install a_callable in to the hook hook_name.
50
52
 
54
56
            The exact signature will depend on the hook - see the __init__ 
55
57
            method of BranchHooks for details on each hook.
56
58
        """
 
59
        self.install_named_hook(hook_name, a_callable, None)
 
60
 
 
61
    def install_named_hook(self, hook_name, a_callable, name):
 
62
        """Install a_callable in to the hook hook_name, and label it name.
 
63
 
 
64
        :param hook_name: A hook name. See the __init__ method of BranchHooks
 
65
            for the complete list of hooks.
 
66
        :param a_callable: The callable to be invoked when the hook triggers.
 
67
            The exact signature will depend on the hook - see the __init__ 
 
68
            method of BranchHooks for details on each hook.
 
69
        :param name: A name to associate a_callable with, to show users what is
 
70
            running.
 
71
        """
57
72
        try:
58
73
            self[hook_name].append(a_callable)
59
74
        except KeyError:
60
75
            raise errors.UnknownHook(self.__class__.__name__, hook_name)
 
76
        if name is not None:
 
77
            self.name_hook(a_callable, name)
61
78
 
62
79
    def name_hook(self, a_callable, name):
63
80
        """Associate name with a_callable to show users what is running."""