~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/cleanup.py

  • Committer: Andrew Bennetts
  • Date: 2009-09-23 06:00:51 UTC
  • mto: (4744.3.1 robust-cleanup-in-commit)
  • mto: This revision was merged to the branch mainline in revision 4775.
  • Revision ID: andrew.bennetts@canonical.com-20090923060051-xmiz3cs0x3bd124h
Add unit test for -Dcleanup behaviour.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
    finally:
43
43
        run_cleanups([cleanup_func_a, cleanup_func_b], ...)
44
44
 
45
 
Developers can use the `-Dcleanup` debug flag to always propagate errors from
46
 
cleanup functions.
 
45
Developers can use the `-Dcleanup` debug flag to cause cleanup errors to be
 
46
reported in the UI as well as logged.
47
47
 
48
48
XXX: what about the case where do_something succeeds, but cleanup fails, and
49
49
that matters?
63
63
    trace,
64
64
    )
65
65
 
66
 
def _log_cleanup_error():
 
66
def _log_cleanup_error(exc):
67
67
    trace.mutter('Cleanup failed:')
68
68
    trace.log_exception_quietly()
 
69
    if 'cleanup' in debug.debug_flags:
 
70
        trace.warning('bzr: warning: Cleanup failed: %s', exc)
69
71
 
70
72
 
71
73
def run_cleanup(func, *args, **kwargs):
78
80
        func(*args, **kwargs)
79
81
    except KeyboardInterrupt:
80
82
        raise
81
 
    except:
82
 
        _log_cleanup_error()
83
 
        if 'cleanup' in debug.debug_flags:
84
 
            raise
85
 
        return False
86
 
    return True
87
 
 
88
 
 
89
 
def run_cleanup_reporting_errors(func, *args, **kwargs):
90
 
    try:
91
 
        func(*args, **kwargs)
92
 
    except KeyboardInterrupt:
93
 
        raise
94
 
    except Exception, e:
95
 
        _log_cleanup_error()
96
 
        trace.warning('Cleanup function %r failed: %s', func, e)
97
 
        if 'cleanup' in debug.debug_flags:
98
 
            raise
99
 
        return False
100
 
    return True
 
83
    except Exception, exc:
 
84
        _log_cleanup_error(exc)
 
85
        return False
 
86
    return True
 
87
 
 
88
 
 
89
#def run_cleanup_reporting_errors(func, *args, **kwargs):
 
90
#    try:
 
91
#        func(*args, **kwargs)
 
92
#    except KeyboardInterrupt:
 
93
#        raise
 
94
#    except Exception, exc:
 
95
#        trace.mutter('Cleanup failed:')
 
96
#        trace.log_exception_quietly()
 
97
#        trace.warning('Cleanup failed: %s', exc)
 
98
#        return False
 
99
#    return True
101
100
 
102
101
 
103
102
def run_cleanups(funcs, on_error='log'):