~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: Jelmer Vernooij
  • Date: 2012-01-02 14:41:49 UTC
  • mto: This revision was merged to the branch mainline in revision 6441.
  • Revision ID: jelmer@samba.org-20120102144149-66kkvew1kylagrk9
Drop exception suppression support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
259
259
        # No command found.
260
260
        raise KeyError
261
261
    # Allow plugins to extend commands
262
 
    Command.hooks['extend_command'].fire(cmd)
 
262
    for hook in Command.hooks['extend_command']:
 
263
        hook(cmd)
263
264
    if getattr(cmd, 'invoked_as', None) is None:
264
265
        cmd.invoked_as = cmd_name
265
266
    return cmd
403
404
        """Construct an instance of this command."""
404
405
        # List of standard options directly supported
405
406
        self.supported_std_options = []
406
 
        self._hook_run()
407
407
        self._setup_run()
408
408
 
409
409
    def add_cleanup(self, cleanup_func, *args, **kwargs):
678
678
                display=('bytes' in debug.debug_flags))
679
679
            trace.set_verbosity_level(0)
680
680
 
681
 
    def _hook_run(self):
682
 
        """Wrap the defined run method on self with command execution hooks.
683
 
 
684
 
        This is called by __init__ to make the Command be able to be run
685
 
        by just calling run(), as it could be before hook executions were added.
686
 
        """
687
 
        class_run = self.run
688
 
        def run(*args, **kwargs):
689
 
            Command.hooks['pre_command'].fire(self)
690
 
            raised = None
691
 
            try:
692
 
                return class_run(*args, **kwargs)
693
 
            except Exception, e:
694
 
                raised = e
695
 
                raise e
696
 
            finally:
697
 
                Command.hooks['post_command'].fire(self, raised)
698
 
        self.run = run
699
 
 
700
681
    def _setup_run(self):
701
682
        """Wrap the defined run method on self with a cleanup.
702
683
 
708
689
        """
709
690
        class_run = self.run
710
691
        def run(*args, **kwargs):
 
692
            for hook in Command.hooks['pre_command']:
 
693
                hook(self)
711
694
            self._operation = cleanup.OperationWithCleanups(class_run)
712
695
            try:
713
696
                return self._operation.run_simple(*args, **kwargs)
714
697
            finally:
715
698
                del self._operation
 
699
                for hook in Command.hooks['post_command']:
 
700
                    hook(self)
716
701
        self.run = run
717
702
 
718
703
    def run(self):
808
793
            (1, 17))
809
794
        self.add_hook('pre_command',
810
795
            "Called prior to executing a command. Called with the command "
811
 
            "object.", (2, 5), suppress_exceptions=True,
812
 
            passed_exceptions=[errors.BzrCommandError])
 
796
            "object.", (2, 5))
813
797
        self.add_hook('post_command',
814
798
            "Called after executing a command. Called with the command "
815
 
            "object and the raised exception (or None). The hook cannot "
816
 
            "affect the raising of the exception.", (2, 5),
817
 
            suppress_exceptions=True,
818
 
            passed_exceptions=[errors.BzrCommandError])
 
799
            "object.", (2, 5))
819
800
 
820
801
Command.hooks = CommandHooks()
821
802