mirror of
https://github.com/SickGear/SickGear.git
synced 2024-11-23 13:25:04 +00:00
31 lines
788 B
Python
31 lines
788 B
Python
|
from hachoir.core.error import warning
|
||
|
|
||
|
|
||
|
def fault_tolerant(func, *args):
|
||
|
def safe_func(*args, **kw):
|
||
|
try:
|
||
|
func(*args, **kw)
|
||
|
except Exception as err:
|
||
|
warning("Error when calling function %s(): %s" % (
|
||
|
func.__name__, err))
|
||
|
return safe_func
|
||
|
|
||
|
|
||
|
def getFieldAttribute(fieldset, key, attrname):
|
||
|
try:
|
||
|
field = fieldset[key]
|
||
|
if field.hasValue():
|
||
|
return getattr(field, attrname)
|
||
|
except Exception as err:
|
||
|
warning("Unable to get %s of field %s/%s: %s" % (
|
||
|
attrname, fieldset.path, key, err))
|
||
|
return None
|
||
|
|
||
|
|
||
|
def getValue(fieldset, key):
|
||
|
return getFieldAttribute(fieldset, key, "value")
|
||
|
|
||
|
|
||
|
def getDisplay(fieldset, key):
|
||
|
return getFieldAttribute(fieldset, key, "display")
|