~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/cleanup.py

  • Committer: Andrew Bennetts
  • Date: 2009-12-16 13:10:03 UTC
  • mto: This revision was merged to the branch mainline in revision 4948.
  • Revision ID: andrew.bennetts@canonical.com-20091216131003-7161dih4q94x3irz
Add add_cleanup to Command.

Show diffs side-by-side

added added

removed removed

Lines of Context:
91
91
 
92
92
    where `some_func` is::
93
93
 
94
 
        def some_func(operation, args, ...)
 
94
        def some_func(operation, args, ...):
95
95
            do_something()
96
96
            operation.add_cleanup(something)
97
97
            # etc
98
98
 
99
99
    Note that the first argument passed to `some_func` will be the
100
 
    OperationWithCleanups object.
 
100
    OperationWithCleanups object.  To invoke `some_func` without that, use
 
101
    `run_simple` instead of `run`.
101
102
    """
102
103
 
103
104
    def __init__(self, func):
116
117
        return _do_with_cleanups(
117
118
            self.cleanups, self.func, self, *args, **kwargs)
118
119
 
 
120
    def run_simple(self, *args, **kwargs):
 
121
        return _do_with_cleanups(
 
122
            self.cleanups, self.func, *args, **kwargs)
 
123
 
119
124
 
120
125
def _do_with_cleanups(cleanup_funcs, func, *args, **kwargs):
121
126
    """Run `func`, then call all the cleanup_funcs.