~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/cleanup.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:
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):
120
121
        return _do_with_cleanups(
121
122
            self.cleanups, self.func, *args, **kwargs)
122
123
 
 
124
    def cleanup_now(self):
 
125
        _run_cleanups(self.cleanups)
 
126
        self.cleanups.clear()
 
127
 
123
128
 
124
129
def _do_with_cleanups(cleanup_funcs, func, *args, **kwargs):
125
130
    """Run `func`, then call all the cleanup_funcs.