예제 #1
0
def exceptionHandler( *args ):
	'''
	This is a generic exception handler that can replace the default python exception handler if
	needed (ie: sys.excepthook=exceptionHandler).  It will mail
	'''
	try:
		eType, e, tb = args
	except TypeError:
		eType, e, tb = sys.exc_info()

	printMsg( '### ERROR - Python Unhandled Exception' )
	printMsg( '### ', eType.__name__, e )

	#
	toolName = findMostRecentDefitionOf( 'TOOL_NAME' ) or '<NO_TOOL>'

	#generate the message
	env = os.environ
	message = 'Subject: [ERROR] %s\n\n%s\n\n%s\n\n%s' % (toolName, cgitb.text( args ), '\n'.join( sys.path ),'\n'.join( [ '%s=%s' % (k, env[ k ]) for k in sorted( env.keys() ) ] ))

	#try to write a log
	fLog = open( 'c:/python_tool_log_%s.txt' % toolName, 'w' )
	try: fLog.write( message )
	except: pass
	finally: fLog.close()

	#try to mail a callstack
	try:
		import smtplib

		author = findMostRecentDefitionOf( '__author__' ) or DEFAULT_AUTHOR
		svr = smtplib.SMTP( 'exchange2' )
		svr.sendmail(os.environ[ 'USERNAME' ], [author, os.environ[ 'USERNAME' ]], message)
	except Exception, x:
		printMsg( 'ERROR: failed to mail exception dump', x )
def exceptionHandler(*args):
    '''
	This is a generic exception handler that can replace the default python exception handler if
	needed (ie: sys.excepthook=exceptionHandler).  It will mail
	'''
    try:
        eType, e, tb = args
    except TypeError:
        eType, e, tb = sys.exc_info()

    printMsg('### ERROR - Python Unhandled Exception')
    printMsg('### ', eType.__name__, e)

    #
    toolName = findMostRecentDefitionOf('TOOL_NAME') or '<NO_TOOL>'

    #generate the message
    env = os.environ
    message = 'Subject: [ERROR] %s\n\n%s\n\n%s\n\n%s' % (
        toolName, cgitb.text(args), '\n'.join(sys.path), '\n'.join(
            ['%s=%s' % (k, env[k]) for k in sorted(env.keys())]))

    #try to write a log
    fLog = open('c:/python_tool_log_%s.txt' % toolName, 'w')
    try:
        fLog.write(message)
    except:
        pass
    finally:
        fLog.close()

    #try to mail a callstack
    try:
        import smtplib

        author = findMostRecentDefitionOf('__author__') or DEFAULT_AUTHOR
        svr = smtplib.SMTP('exchange2')
        svr.sendmail(os.environ['USERNAME'], [author, os.environ['USERNAME']],
                     message)
    except Exception, x:
        printMsg('ERROR: failed to mail exception dump', x)
def exceptionHandler(*args):
    """
	This is a generic exception handler that can replace the default python exception handler if
	needed (ie: sys.excepthook=exceptionHandler).  It will mail
	"""
    try:
        eType, e, tb = args
    except TypeError:
        eType, e, tb = sys.exc_info()

    printMsg("### ERROR - Python Unhandled Exception")
    printMsg("### ", eType.__name__, e)

    # try to mail a callstack
    try:
        import smtplib

        message = "Subject: [ERROR] assetEditor\n\n%s" % cgitb.text(args)

        author = findMostRecentDefitionOf("__author__") or DEFAULT_AUTHOR
        svr = smtplib.SMTP("exchange2")
        svr.sendmail(os.environ["USERNAME"], [author, os.environ["USERNAME"]], message)
    except Exception, x:
        printMsg("ERROR: failed to mail exception dump", x)
예제 #4
0
def exceptionHandler(*args):
    '''
	This is a generic exception handler that can replace the default python exception handler if
	needed (ie: sys.excepthook=exceptionHandler).  It will mail
	'''
    try:
        eType, e, tb = args
    except TypeError:
        eType, e, tb = sys.exc_info()

    printMsg('### ERROR - Python Unhandled Exception')
    printMsg('### ', eType.__name__, e)

    #try to mail a callstack
    try:
        import smtplib
        message = 'Subject: [ERROR] assetEditor\n\n%s' % cgitb.text(args)

        author = findMostRecentDefitionOf('__author__') or DEFAULT_AUTHOR
        svr = smtplib.SMTP('exchange2')
        svr.sendmail(os.environ['USERNAME'], [author, os.environ['USERNAME']],
                     message)
    except Exception, x:
        printMsg('ERROR: failed to mail exception dump', x)