~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/hooks.py

  • Committer: Daniel Watkins
  • Date: 2008-03-08 23:15:36 UTC
  • mto: (3394.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 3395.
  • Revision ID: d.m.watkins@warwick.ac.uk-20080308231536-t7h3ox4docehlfqa
Added install_named_hook.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
        """
46
46
        return self._callable_names.get(a_callable, "No hook name")
47
47
 
48
 
    def install_hook(self, hook_name, a_callable, name=None):
49
 
        """Install a_callable in to the hook hook_name.
 
48
    def install_named_hook(self, hook_name, a_callable, name):
 
49
        """Install a_callable in to the hook hook_name, and label it name.
50
50
 
51
51
        :param hook_name: A hook name. See the __init__ method of BranchHooks
52
52
            for the complete list of hooks.
58
58
        """
59
59
        try:
60
60
            self[hook_name].append(a_callable)
61
 
            if callable_name is not None:
 
61
            if name is not None:
62
62
                self.name_hook(a_callable, name)
63
63
        except KeyError:
64
64
            raise errors.UnknownHook(self.__class__.__name__, hook_name)
65
65
 
 
66
    def install_hook(self, hook_name, a_callable):
 
67
        """Install a_callable in to the hook hook_name.
 
68
 
 
69
        :param hook_name: A hook name. See the __init__ method of BranchHooks
 
70
            for the complete list of hooks.
 
71
        :param a_callable: The callable to be invoked when the hook triggers.
 
72
            The exact signature will depend on the hook - see the __init__ 
 
73
            method of BranchHooks for details on each hook.
 
74
        """
 
75
        try:
 
76
            self[hook_name].append(a_callable)
 
77
        except KeyError:
 
78
            raise errors.UnknownHook(self.__class__.__name__, hook_name)
 
79
 
66
80
    def name_hook(self, a_callable, name):
67
81
        """Associate name with a_callable to show users what is running."""
68
82
        self._callable_names[a_callable] = name