~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/hooks.py

  • Committer: Ian Clatworthy
  • Date: 2008-03-27 07:51:10 UTC
  • mto: (3311.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 3312.
  • Revision ID: ian.clatworthy@canonical.com-20080327075110-afgd7x03ybju06ez
Reduce evangelism in the User Guide

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007, 2008 Canonical Ltd
 
1
# Copyright (C) 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
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
21
20
lazy_import(globals(), """
22
21
from bzrlib import (
23
22
        errors,
46
45
        """
47
46
        return self._callable_names.get(a_callable, "No hook name")
48
47
 
49
 
    @deprecated_method(one_five)
50
48
    def install_hook(self, hook_name, a_callable):
51
49
        """Install a_callable in to the hook hook_name.
52
50
 
56
54
            The exact signature will depend on the hook - see the __init__ 
57
55
            method of BranchHooks for details on each hook.
58
56
        """
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
 
        """
72
57
        try:
73
58
            self[hook_name].append(a_callable)
74
59
        except KeyError:
75
60
            raise errors.UnknownHook(self.__class__.__name__, hook_name)
76
 
        if name is not None:
77
 
            self.name_hook(a_callable, name)
78
61
 
79
62
    def name_hook(self, a_callable, name):
80
63
        """Associate name with a_callable to show users what is running."""