~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/hooks.py

  • Committer: Robert Collins
  • Date: 2007-06-28 03:08:53 UTC
  • mto: This revision was merged to the branch mainline in revision 2560.
  • Revision ID: robertc@robertcollins.net-20070628030853-fjeb7ii5euyvi7c1
Give Hooks names.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
    FOO hook is triggered.
32
32
    """
33
33
 
 
34
    def __init__(self):
 
35
        dict.__init__(self)
 
36
        self._callable_names = {}
 
37
 
 
38
    def get_hook_name(self, a_callable):
 
39
        """Get the name for a_callable for UI display.
 
40
 
 
41
        If no name has been registered, the string 'No hook name' is returned.
 
42
        """
 
43
        return self._callable_names.get(a_callable, "No hook name")
 
44
 
34
45
    def install_hook(self, hook_name, a_callable):
35
46
        """Install a_callable in to the hook hook_name.
36
47
 
44
55
            self[hook_name].append(a_callable)
45
56
        except KeyError:
46
57
            raise errors.UnknownHook(self.__class__.__name__, hook_name)
 
58
 
 
59
    def name_hook(self, a_callable, name):
 
60
        """Associate name with a_callable to show users what is running."""
 
61
        self._callable_names[a_callable] = name