~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: Andrew Bennetts
  • Date: 2010-01-13 23:16:20 UTC
  • mfrom: (4957 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4960.
  • Revision ID: andrew.bennetts@canonical.com-20100113231620-n6in2yjib2v6z03g
MergeĀ lp:bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
 
41
41
import bzrlib
42
42
from bzrlib import (
 
43
    cleanup,
43
44
    debug,
44
45
    errors,
45
46
    option,
384
385
            warn("No help message set for %r" % self)
385
386
        # List of standard options directly supported
386
387
        self.supported_std_options = []
387
 
 
 
388
        self._operation = cleanup.OperationWithCleanups(self.run)
 
389
    
 
390
    def add_cleanup(self, cleanup_func, *args, **kwargs):
 
391
        """Register a function to call after self.run returns or raises.
 
392
 
 
393
        Functions will be called in LIFO order.
 
394
        """
 
395
        self._operation.add_cleanup(cleanup_func, *args, **kwargs)
 
396
 
 
397
    def cleanup_now(self):
 
398
        """Execute and empty pending cleanup functions immediately.
 
399
 
 
400
        After cleanup_now all registered cleanups are forgotten.  add_cleanup
 
401
        may be called again after cleanup_now; these cleanups will be called
 
402
        after self.run returns or raises (or when cleanup_now is next called).
 
403
 
 
404
        This is useful for releasing expensive or contentious resources (such
 
405
        as write locks) before doing further work that does not require those
 
406
        resources (such as writing results to self.outf).
 
407
        """
 
408
        self._operation.cleanup_now()
 
409
        
388
410
    @deprecated_method(deprecated_in((2, 1, 0)))
389
411
    def _maybe_expand_globs(self, file_list):
390
412
        """Glob expand file_list if the platform does not do that itself.
511
533
                        # so don't create a real link
512
534
                        see_also_links.append(item)
513
535
                    else:
514
 
                        # Use a reST link for this entry
515
 
                        see_also_links.append("`%s`_" % (item,))
 
536
                        # Use a Sphinx link for this entry
 
537
                        link_text = ":doc:`%s <%s-help>`" % (item, item)
 
538
                        see_also_links.append(link_text)
516
539
                see_also = see_also_links
517
540
            result += ':See also: '
518
541
            result += ', '.join(see_also) + '\n'
635
658
 
636
659
        self._setup_outf()
637
660
 
638
 
        return self.run(**all_cmd_args)
 
661
        return self.run_direct(**all_cmd_args)
 
662
 
 
663
    def run_direct(self, *args, **kwargs):
 
664
        """Call run directly with objects (without parsing an argv list)."""
 
665
        return self._operation.run_simple(*args, **kwargs)
639
666
 
640
667
    def run(self):
641
668
        """Actually run the command.
927
954
    --concurrency
928
955
        Specify the number of processes that can be run concurrently (selftest).
929
956
    """
 
957
    trace.mutter("bazaar version: " + bzrlib.__version__)
930
958
    argv = list(argv)
931
959
    trace.mutter("bzr arguments: %r", argv)
932
960