Source code for classes.exceptions_omfit

# file processed by 2to3
from __future__ import print_function, absolute_import
from builtins import map, filter, range

import sys
import signal
import traceback

if sys.version_info >= (3,0):
    basestring=str





#---------------------
# OMFIT exceptions
#---------------------
[docs]class doNotReportException(object): ''' Exceptions that inherit from this class will not trigger an email sent be set to the OMFIT developer team ''' pass
[docs]class EndOMFITpython(KeyboardInterrupt, doNotReportException): """ Class used to stop the running python script without reporting it to the OMFIT developer team """ def __init__(self, message='', *args, **kw): KeyboardInterrupt.__init__(self, message, *args, **kw) if isinstance(message, basestring) and len(message): print(message, file=sys.stderr)
[docs]class EndAllOMFITpython(KeyboardInterrupt, doNotReportException): """ Class used to stop the entire python workflow without reporting it to the OMFIT developer team """ def __init__(self, message='', *args, **kw): KeyboardInterrupt.__init__(self, message, *args, **kw) if isinstance(message, basestring) and len(message): print(message, file=sys.stderr)
[docs]class OMFITexception(Exception, doNotReportException): """ Class used to raise an exception in a user's script without reporting it to the OMFIT developer team """ def __init__(self, message='', *args, **kw): Exception.__init__(self, message, *args, **kw)
[docs]class ReturnCodeException(RuntimeError): """ Class used to raise an exception when a code return code is !=0 """ pass
[docs]def signalHandler(signal=None, frame=None): raise EndAllOMFITpython('\n\n---> Aborted by user <---\n\n')
try: signal.signal(signal.SIGTERM, signalHandler) except ValueError: #ValueError: signal only works in main thread pass __all__=['print_last_exception', 'print_stack', 'doNotReportException', 'EndOMFITpython', 'EndAllOMFITpython', 'OMFITexception', 'ReturnCodeException', 'signalHandler']