~scode/duplicity/misc

« back to all changes in this revision

Viewing changes to duplicity/util.py

  • Committer: Peter Schuller
  • Date: 2009-07-08 16:51:59 UTC
  • mfrom: (548.1.10 duplicity-src)
  • Revision ID: peter.schuller@infidyne.com-20090708165159-v65s0znz09fnq29w
* merge latest trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
import sys
28
28
import traceback
29
29
 
 
30
import duplicity.globals as globals
 
31
import duplicity.log as log
 
32
 
30
33
def exception_traceback(limit = 50):
31
34
    """
32
35
    @return A string representation in typical Python format of the
46
49
def escape(string):
47
50
    return "'%s'" % string.encode("string-escape")
48
51
 
 
52
def maybe_ignore_errors(fn):
 
53
    """
 
54
    Execute fn. If the global configuration setting ignore_errors is
 
55
    set to True, catch errors and log them but do continue (and return
 
56
    None).
 
57
 
 
58
    @param fn: A callable.
 
59
    @return Whatever fn returns when called, or None if it failed and ignore_errors is true.
 
60
    """
 
61
    try:
 
62
        return fn()
 
63
    except Exception, e:
 
64
        if globals.ignore_errors:
 
65
            log.Warn(_("IGNORED_ERROR: Warning: ignoring error as requested: %s: %s")
 
66
                     % (e.__class__.__name__, str(e)))
 
67
            return None
 
68
        else:
 
69
            raise