# 2013-03-06 johnpfeiffer
from functools import wraps
def skip( ExceptionsToCheck , logger = None ):
"""Skip and Log if one of the Exceptions provided is raised
:ExceptionsToCheck: tuple of exceptions to check
:logger: logger to use. If None, print
"""
def deco_skip( f ):
@wraps( f )
def f_skip( *args , **kwargs ):
try:
return f( *args , **kwargs )
except ExceptionsToCheck as error:
message = "SKIPPING due to %s" % ( str( error ) )
if logger:
logger.warning( message )
else:
print message
return
return f_skip # true decorator
return deco_skip
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# 2013-03-06 johnpfeiffer
from functools import wraps
import o2lib
def skip_apisystemsexception_duplicate( logger = None ):
"""Skip and Log if one of the Exceptions provided is raised
:ExceptionsToCheck: tuple of exceptions to check
:logger: logger to use. If None, print
"""
def deco_skip( f ):
@wraps( f )
def f_skip( *args , **kwargs ):
try:
return f( *args , **kwargs )
except o2lib.ApiSystemsException as error:
if error.errorCode == 2:
error_detail = o2lib.ApiSystemsErrorCode._VALUES_TO_NAMES[ error.errorCode ]
message = "SKIPPING: %s due to %s %s" % ( error_detail , str( error ) , repr( args ) )
if logger:
logger.warning( message )
else:
print message
return # skip continuing the function
raise error # if reached then propogate the error back up
return f_skip # true decorator
return deco_skip