~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/hooks.py

  • Committer: v.ladeuil+lp at free
  • Date: 2007-05-18 18:20:31 UTC
  • mto: (2485.8.44 bzr.connection.sharing)
  • mto: This revision was merged to the branch mainline in revision 2646.
  • Revision ID: v.ladeuil+lp@free.fr-20070518182031-gbg2cgidv5l20x9p
Takes Robert comments into account.

* bzrlib/transport/ftp.py:
(FtpTransport.__init__): Write a better explanation.

* bzrlib/tests/test_init.py:
(InstrumentedTransport): Just make hooks a class attribute.
(InstrumentedTransport._get_FTP): Run hook directly in the for
loop.
(TransportHooks.run_hook, TransportHooks.uninstall_hook): Not
needed. The hooks should be cleaned up by the test itself.
(TestInit.setUp.cleanup): Resset to default hooks.

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
 
        We use a fixed string rather than repr or the callables module because
43
 
        the code names are rarely meaningful for end users and this is not 
44
 
        intended for debugging.
45
 
        """
46
 
        return self._callable_names.get(a_callable, "No hook name")
47
 
 
48
34
    def install_hook(self, hook_name, a_callable):
49
35
        """Install a_callable in to the hook hook_name.
50
36
 
58
44
            self[hook_name].append(a_callable)
59
45
        except KeyError:
60
46
            raise errors.UnknownHook(self.__class__.__name__, hook_name)
61
 
 
62
 
    def name_hook(self, a_callable, name):
63
 
        """Associate name with a_callable to show users what is running."""
64
 
        self._callable_names[a_callable] = name