~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: Patch Queue Manager
  • Date: 2012-01-18 20:08:49 UTC
  • mfrom: (6240.5.9 pre_post_command_hooks)
  • Revision ID: pqm@pqm.ubuntu.com-20120118200849-i93mg9cvcwxpvth3
(jelmer) Add pre_command and post_command hooks. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
689
689
        """
690
690
        class_run = self.run
691
691
        def run(*args, **kwargs):
 
692
            for hook in Command.hooks['pre_command']:
 
693
                hook(self)
692
694
            self._operation = cleanup.OperationWithCleanups(class_run)
693
695
            try:
694
696
                return self._operation.run_simple(*args, **kwargs)
695
697
            finally:
696
698
                del self._operation
 
699
                for hook in Command.hooks['post_command']:
 
700
                    hook(self)
697
701
        self.run = run
698
702
 
699
703
    def run(self):
787
791
            " is safe to mutate - e.g. to remove a command. "
788
792
            "list_commands should return the updated set of command names.",
789
793
            (1, 17))
 
794
        self.add_hook('pre_command',
 
795
            "Called prior to executing a command. Called with the command "
 
796
            "object.", (2, 5))
 
797
        self.add_hook('post_command',
 
798
            "Called after executing a command. Called with the command "
 
799
            "object.", (2, 5))
790
800
 
791
801
Command.hooks = CommandHooks()
792
802