~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/cleanup.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-11-17 03:20:35 UTC
  • mfrom: (4792.4.3 456036)
  • Revision ID: pqm@pqm.ubuntu.com-20091117032035-s3sgtlixj1lrminn
(Gordon Tyler) Fix IndexError during 'bzr ignore /' (#456036)

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.  To invoke `some_func` without that, use
101
 
    `run_simple` instead of `run`.
 
100
    OperationWithCleanups object.
102
101
    """
103
102
 
104
103
    def __init__(self, func):
117
116
        return _do_with_cleanups(
118
117
            self.cleanups, self.func, self, *args, **kwargs)
119
118
 
120
 
    def run_simple(self, *args, **kwargs):
121
 
        return _do_with_cleanups(
122
 
            self.cleanups, self.func, *args, **kwargs)
123
 
 
124
 
    def cleanup_now(self):
125
 
        _run_cleanups(self.cleanups)
126
 
        self.cleanups.clear()
127
 
 
128
119
 
129
120
def _do_with_cleanups(cleanup_funcs, func, *args, **kwargs):
130
121
    """Run `func`, then call all the cleanup_funcs.