Example #1
0
def pyExceptionToCORBA(native_ex):
    '''
    Useful function which converts a native Python function to an ACS Error
    System CORBA exception. This is only to be used in situations
    immediately after the native Python exception has can been caught.
    Such an example is:
        try:
            print joe
        except NameError, ex:
            corba_ex = pyExceptionToCORBA(ex)
            raise corba_ex

    Parameters:
    - native_ex is a native Python exception. This should not be derived
    from any CORBA class.

    Returns: native_ex converted to a
    ACSErrTypePythonNativeImpl.ACSErrTypePythonNativeExImpl

    Raises: ???
    '''
    from traceback import format_exc
    from Acspy.Common.ErrorTrace import ErrorTrace
    from ACSErrTypePythonNativeImpl import PythonExImpl
    
    #first let's get the traceback in string format
    string_tb = format_exc()

    #next get the type of native_ex. this will be used as the short
    #description
    descript = native_ex.__doc__

    #create the new exception
    new_except = PythonExImpl()

    #redo the error trace so that the level is one lower
    new_et = ErrorTrace(new_except.getErrorType(),
                        new_except.getErrorCode(),
                        description = new_except.getDescription(),
                        level = 2)
    new_except.setErrorTrace(new_et)

    #time to add the real description
    new_except.addData("Real Description", descript)

    #add the real traceback
    new_except.addData("Traceback", string_tb)

    return new_except
Example #2
0
    def __init__(self,
                 error_type,
                 error_code,
                 exception=None,
                 description="None",
                 nvSeq=None,
                 level=3,
                 severity=None,
                 sourceobject=""):
        '''
        Parameters:
        - error_type is the error type (a long)
        - error_code is the error code (a long)
        - exception is a previous exception from the ACS Error System, or a Python 
	native exception, in which case, an ErrorTrace will be constructed. The traceback
	should be ok in most cases, but if you find that it isn't, a possible workaround is
	converting the python exception to an ACS exception using pyExceptionToCORBA()
	before passing it to an ACSError constructor. Remember, that if you don't use 
	pyExceptionToCORBA(), if 
	you are dealing with a native exception, you must pass create=1 to the ACSError 
	constructor.
        - description is a stringified description of the errror
        - nvSeq is a name-value sequence describing the error condition. Each value
        should be of the type ACSErr.NameValue
        - level is an offset from stack()
        - severity is the severity of the error
        '''
        call_frame = stack()[level]

        if nvSeq == None:
            nvSeq = []

        #Get the file name
        filename = str(call_frame[1])

        #Get the line number
        line = str(call_frame[2])

        #Get the routine name
        routine = str(call_frame[3])

        #Get the hostname
        host = gethostname()

        #Get the process ID
        process = str(getpid())

        #Try to get the thread ID
        if currentThread() != None:
            thread = str(currentThread().getName())
        else:
            thread = "Unavailable"

        #Get the ACS time
        time = getTimeStamp().value

        # Client, components and containers have
        frame = call_frame[0]
        if 'self' in frame.f_locals and 'name' in frame.f_locals[
                'self'].__dict__:
            sourceObject = frame.f_locals['self'].name
        else:
            sourceObject = sourceobject

        #Set the severity
        if severity == None:
            severity = ACSErr.Error

#let's get the traceback in case we are dealing
#with a Python native exception
        from traceback import extract_tb, format_exc
        string_tb = format_exc()
        from sys import exc_info
        tuple_tb = extract_tb(exc_info()[2])
        try:
            #If the previous exception is an ACS Error System Exception
            if isinstance(exception.errorTrace, ACSErr.ErrorTrace):
                #We can use an error stack...
                errortrace = [exception.errorTrace]
        except Exception, e:
            if exception == None:
                errortrace = []
            else:
                #In this case we are dealing with a native Python Exception
                #so we have to "transform" it to an ACS exception
                #(actually we are only interested in the ErrorTrace)
                from ACSErrTypePythonNativeImpl import PythonExImpl

                #next get the type of native_ex. this will be used as the short
                #description
                descript = exception.__doc__

                #create the new exception
                new_except = PythonExImpl()

                #redo the error trace so that the level is one lower
                new_et = ErrorTrace(new_except.getErrorType(),
                                    new_except.getErrorCode(),
                                    description=new_except.getDescription(),
                                    level=2,
                                    sourceobject=sourceObject)

                #Now modify some fields
                new_et.file = tuple_tb[0][0]
                new_et.lineNum = tuple_tb[0][1]
                new_et.routine = tuple_tb[0][2]

                new_except.setErrorTrace(new_et)

                #time to add the real description
                new_except.addData("Real Description", descript)

                #add the real traceback
                new_except.addData("Traceback", string_tb)

                errortrace = [new_except.errorTrace]
Example #3
0
    def __init__(self,
                 error_type,
                 error_code,
                 exception = None,
                 description = "None", 
                 nvSeq = None,
                 level = 3,
                 severity = None,
                 sourceobject = ""):
        '''
        Parameters:
        - error_type is the error type (a long)
        - error_code is the error code (a long)
        - exception is a previous exception from the ACS Error System, or a Python 
	native exception, in which case, an ErrorTrace will be constructed. The traceback
	should be ok in most cases, but if you find that it isn't, a possible workaround is
	converting the python exception to an ACS exception using pyExceptionToCORBA()
	before passing it to an ACSError constructor. Remember, that if you don't use 
	pyExceptionToCORBA(), if 
	you are dealing with a native exception, you must pass create=1 to the ACSError 
	constructor.
        - description is a stringified description of the errror
        - nvSeq is a name-value sequence describing the error condition. Each value
        should be of the type ACSErr.NameValue
        - level is an offset from stack()
        - severity is the severity of the error
        '''
        call_frame = stack()[level]
        
        if nvSeq == None:
            nvSeq = []
    
        #Get the file name
        filename = str(call_frame[1])
    
        #Get the line number
        line = str(call_frame[2])
    
        #Get the routine name
        routine = str(call_frame[3])
    
        #Get the hostname
        host = gethostname()
    
        #Get the process ID
        process = str(getpid())
        
        #Try to get the thread ID
        if currentThread() != None:
            thread = str(currentThread().getName())
        else:
            thread = "Unavailable"
            
        #Get the ACS time
        time = getTimeStamp().value
            
        # Client, components and containers have 
        frame = call_frame[0]
        if 'self' in frame.f_locals and 'name' in frame.f_locals['self'].__dict__:
            sourceObject = frame.f_locals['self'].name
        else:
            sourceObject = sourceobject
        
        #Set the severity
        if severity == None:
            severity = ACSErr.Error
            
	
	#let's get the traceback in case we are dealing
	#with a Python native exception
	from traceback import extract_tb,format_exc
	string_tb=format_exc()
	from sys import exc_info
	tuple_tb=extract_tb(exc_info()[2])
        try:
            #If the previous exception is an ACS Error System Exception
            if isinstance(exception.errorTrace, ACSErr.ErrorTrace):
                #We can use an error stack...
                errortrace = [ exception.errorTrace ]
        except Exception, e:
           if exception == None:
                errortrace = []
           else:	
		#In this case we are dealing with a native Python Exception
		#so we have to "transform" it to an ACS exception
		#(actually we are only interested in the ErrorTrace)
                from ACSErrTypePythonNativeImpl import PythonExImpl
		

                #next get the type of native_ex. this will be used as the short
                #description
                descript = exception.__doc__

                #create the new exception
                new_except = PythonExImpl()

                #redo the error trace so that the level is one lower
                new_et = ErrorTrace(new_except.getErrorType(),
                                    new_except.getErrorCode(),
                                    description = new_except.getDescription(),
                                    level = 2, sourceobject=sourceObject)

		#Now modify some fields
		new_et.file=tuple_tb[0][0]
		new_et.lineNum=tuple_tb[0][1]
		new_et.routine=tuple_tb[0][2]

                new_except.setErrorTrace(new_et)

                #time to add the real description
                new_except.addData("Real Description", descript)

    		#add the real traceback
    		new_except.addData("Traceback", string_tb)


                errortrace= [ new_except.errorTrace ]
Example #4
0
def pyExceptionToCORBA(native_ex):
    '''
    Useful function which converts a native Python function to an ACS Error
    System CORBA exception. This is only to be used in situations
    immediately after the native Python exception has can been caught.
    Such an example is:
        try:
            print joe
        except NameError, ex:
            corba_ex = pyExceptionToCORBA(ex)
            raise corba_ex

    Parameters:
    - native_ex is a native Python exception. This should not be derived
    from any CORBA class.

    Returns: native_ex converted to a
    ACSErrTypePythonNativeImpl.ACSErrTypePythonNativeExImpl

    Raises: ???
    '''
    from traceback import format_exc
    from Acspy.Common.ErrorTrace import ErrorTrace
    from ACSErrTypePythonNativeImpl import PythonExImpl

    #first let's get the traceback in string format
    string_tb = format_exc()

    #next get the type of native_ex. this will be used as the short
    #description
    descript = native_ex.__doc__

    #create the new exception
    new_except = PythonExImpl()

    #redo the error trace so that the level is one lower
    new_et = ErrorTrace(new_except.getErrorType(),
                        new_except.getErrorCode(),
                        description=new_except.getDescription(),
                        level=2)
    new_except.setErrorTrace(new_et)

    #time to add the real description
    new_except.addData("Real Description", descript)

    #add the real traceback
    new_except.addData("Traceback", string_tb)

    return new_except