/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: Robert Collins
  • Date: 2010-05-06 11:08:10 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506110810-h3j07fh5gmw54s25
Cleaner matcher matching revised unlocking protocol.

Show diffs side-by-side

added added

removed removed

Lines of Context:
411
411
            warn("No help message set for %r" % self)
412
412
        # List of standard options directly supported
413
413
        self.supported_std_options = []
414
 
        self._operation = cleanup.OperationWithCleanups(self.run)
 
414
        self._setup_run()
415
415
 
416
416
    def add_cleanup(self, cleanup_func, *args, **kwargs):
417
417
        """Register a function to call after self.run returns or raises.
429
429
 
430
430
        This is useful for releasing expensive or contentious resources (such
431
431
        as write locks) before doing further work that does not require those
432
 
        resources (such as writing results to self.outf).
 
432
        resources (such as writing results to self.outf). Note though, that
 
433
        as it releases all resources, this may release locks that the command
 
434
        wants to hold, so use should be done with care.
433
435
        """
434
436
        self._operation.cleanup_now()
435
437
 
680
682
 
681
683
        self._setup_outf()
682
684
 
683
 
        return self.run_direct(**all_cmd_args)
684
 
 
 
685
        return self.run(**all_cmd_args)
 
686
 
 
687
    def _setup_run(self):
 
688
        """Wrap the defined run method on self with a cleanup.
 
689
 
 
690
        This is called by __init__ to make the Command be able to be run
 
691
        by just calling run(), as it could be before cleanups were added.
 
692
 
 
693
        If a different form of cleanups are in use by your Command subclass,
 
694
        you can override this method.
 
695
        """
 
696
        class_run = self.run
 
697
        def run(*args, **kwargs):
 
698
            self._operation = cleanup.OperationWithCleanups(class_run)
 
699
            try:
 
700
                return self._operation.run_simple(*args, **kwargs)
 
701
            finally:
 
702
                del self._operation
 
703
        self.run = run
 
704
 
 
705
    @deprecated_method(deprecated_in((2, 2, 0)))
685
706
    def run_direct(self, *args, **kwargs):
686
 
        """Call run directly with objects (without parsing an argv list)."""
687
 
        return self._operation.run_simple(*args, **kwargs)
 
707
        """Deprecated thunk from bzrlib 2.1."""
 
708
        return self.run(*args, **kwargs)
688
709
 
689
710
    def run(self):
690
711
        """Actually run the command.
695
716
        Return 0 or None if the command was successful, or a non-zero
696
717
        shell error code if not.  It's OK for this method to allow
697
718
        an exception to raise up.
 
719
 
 
720
        This method is automatically wrapped by Command.__init__ with a 
 
721
        cleanup operation, stored as self._operation. This can be used
 
722
        via self.add_cleanup to perform automatic cleanups at the end of
 
723
        run().
 
724
 
 
725
        The argument for run are assembled by introspection. So for instance,
 
726
        if your command takes an argument files, you would declare::
 
727
 
 
728
            def run(self, files=None):
 
729
                pass
698
730
        """
699
731
        raise NotImplementedError('no implementation of command %r'
700
732
                                  % self.name())