/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/cleanup.py

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
 
46
46
from collections import deque
47
47
import sys
48
 
from . import (
 
48
from bzrlib import (
49
49
    debug,
50
50
    trace,
51
51
    )
54
54
    trace.mutter('Cleanup failed:')
55
55
    trace.log_exception_quietly()
56
56
    if 'cleanup' in debug.debug_flags:
57
 
        trace.warning('brz: warning: Cleanup failed: %s', exc)
 
57
        trace.warning('bzr: warning: Cleanup failed: %s', exc)
58
58
 
59
59
 
60
60
def _run_cleanup(func, *args, **kwargs):
67
67
        func(*args, **kwargs)
68
68
    except KeyboardInterrupt:
69
69
        raise
70
 
    except Exception as exc:
 
70
    except Exception, exc:
71
71
        _log_cleanup_error(exc)
72
72
        return False
73
73
    return True
161
161
    Unike `_run_cleanup`, `_do_with_cleanups` can propagate an exception from a
162
162
    cleanup, but only if there is no exception from func.
163
163
    """
 
164
    # As correct as Python 2.4 allows.
164
165
    try:
165
166
        result = func(*args, **kwargs)
166
167
    except:
167
168
        # We have an exception from func already, so suppress cleanup errors.
168
169
        _run_cleanups(cleanup_funcs)
169
170
        raise
170
 
    # No exception from func, so allow first cleanup error to propgate.
171
 
    pending_cleanups = iter(cleanup_funcs)
172
 
    try:
173
 
        for cleanup, c_args, c_kwargs in pending_cleanups:
174
 
            cleanup(*c_args, **c_kwargs)
175
 
    except:
176
 
        # Still run the remaining cleanups but suppress any further errors.
177
 
        _run_cleanups(pending_cleanups)
178
 
        raise
179
 
    # No error, so we can return the result
180
 
    return result
 
171
    else:
 
172
        # No exception from func, so allow the first exception from
 
173
        # cleanup_funcs to propagate if one occurs (but only after running all
 
174
        # of them).
 
175
        exc_info = None
 
176
        for cleanup, c_args, c_kwargs in cleanup_funcs:
 
177
            # XXX: Hmm, if KeyboardInterrupt arrives at exactly this line, we
 
178
            # won't run all cleanups... perhaps we should temporarily install a
 
179
            # SIGINT handler?
 
180
            if exc_info is None:
 
181
                try:
 
182
                    cleanup(*c_args, **c_kwargs)
 
183
                except:
 
184
                    # This is the first cleanup to fail, so remember its
 
185
                    # details.
 
186
                    exc_info = sys.exc_info()
 
187
            else:
 
188
                # We already have an exception to propagate, so log any errors
 
189
                # but don't propagate them.
 
190
                _run_cleanup(cleanup, *c_args, **kwargs)
 
191
        if exc_info is not None:
 
192
            try:
 
193
                raise exc_info[0], exc_info[1], exc_info[2]
 
194
            finally:
 
195
                del exc_info
 
196
        # No error, so we can return the result
 
197
        return result
 
198
 
 
199