def userInterfaceExceptionTest(): exceptionName = tse.USER_INTERFACE_EXCEPTION for errorName in tse.UserInterfaceException.errorNames: message = 'Test(%s, %s)' % (exceptionName, errorName) myLogger.debug('***** %s / %s *****' % (exceptionName, errorName)) try: raise tse.UserInterfaceException(errorName, message) except tse.UserInterfaceException as e1: tse.displayError(e1) except Exception as e1: sys.stderr.write('Unknown exception: %s' % e1)
def programExceptionTest(): exceptionName = tse.PROGRAM_EXCEPTION for errorName in tse.ProgramException.errorNames: message = 'Test(%s, %s)' % (exceptionName, errorName) myLogger.debug('***** %s / %s *****' % (exceptionName, errorName)) try: raise tse.ProgramException(errorName, message) except tse.ProgramException as e1: tse.displayError(e1) except Exception as e1: sys.stderr.write('Unknown exception: %s' % e1)
def inputoutputExceptionTest(): exceptionName = tse.INPUT_OUTPUT_EXCEPTION for errorName in tse.InputOutputException.errorNames: message = 'Test(%s, %s)' % (exceptionName, errorName) myLogger.debug('***** %s / %s *****' % (exceptionName, errorName)) try: raise tse.InputOutputException(errorName, message) except tse.InputOutputException as e1: tse.displayError(e1) except Exception as e1: sys.stderr.write('Unknown exception: %s' % e1)
def prototype(*args, **kw): ''' Simulated main program entry point with simulated exception inducing exit test. ''' print('\n%s\n' % getRunTimeTitleVersionDate()) rawArgsOptions = sys.argv[1:] print('\trawArgsOptions=%s' % str(rawArgsOptions)) maxArgs = len(rawArgsOptions) theModule = tsOperatorSettingsParser theClass = theModule.TsOperatorSettingsParser() (args, options) = theClass.parseCommandLineDispatch() if True or DEBUG: print('\n\ttsCommandLineEnv.prototype (parameter list): ' + \ '\n\t\targs=%s;\n\t\tkw=%s' % (str(args), str(kw))) print('\n\ttsCommandLineEnv.prototype (command line argv): ' + \ '\n\t\targs=%s;\n\t\toptions (unsorted)=%s' % ( str(args), str(options))) fmt1 = '\n\ttsCommandLineEnv.prototype (command line argv): ' fmt2 = '\n\t\targs (positional) =%s' % str(args) keys = sorted(options.keys()) text = '' for key in keys: value = '"%s"' % options[key] if text == '': text = '{%s: %s' % (str(key), str(value)) else: text += ', %s: %s' % (str(key), str(value)) text += '}' fmt3 = '\n\t\toptions (sorted)= %s' % text msg = fmt1 + fmt2 + fmt3 print(msg) try: myLogger = tsLogger.TsLogger( threshold = tsLogger.DEBUG, start = time.time(), name = 'testDisplay.log') ## myLogger = tsLogger.TsLogger( ## threshold = tsLogger.DEBUG, ## name = ' ') myLogger.notice('About to invoke displayTest') testApplication = displayTest(myLogger) except Exception as e: if isinstance(e, tse.TsExceptions): msg = str(e) tse.displayError(e) exitStatus = e.exitCode else: msg = None sys.stderr.write(traceback.format_exc()) exitStatus = tse.INVALID_ERROR_CODE
## guiTopLevelObjectParent=None, ## guiTopLevelObjectTitle=None, logs=[tsLogger.StandardOutputFile, 'Dummy#2', 'Dummy#3'], runTimeEntryPoint=prototype) results = (theApplication.args, theApplication.options) print('results="%s"' % str(results)) theAssignedLogger = theApplication.logger theApplication.runMainApplication() except Exception as applicationError: if isinstance(applicationError, tse.TsExceptions): msg = str(applicationError).replace("'", "") tse.displayError(applicationError) exitStatus = applicationError.exitCode else: msg = None sys.stderr.write(traceback.format_exc()) exitStatus = tse.INVALID_ERROR_CODE if msg == tse.NO_ERROR: sys.stdout.write(msg) elif msg is not None: sys.stderr.write(msg) # Return (exitStatus) sys.exit(exitStatus)
buildCopyright=__copyright__, buildLicense=__license__, buildCredits=__credits__, buildTitleVersionDate=mainTitleVersionDate, buildHeader=__header__, # getOptions=getOptions, runTimeTitle='main', logs=[], runTimeEntryPoint=theMainApplication) theApplication.runMainApplication() except Exception as e: if isinstance(e, tse.TsExceptions): msg = str(e).replace("'", "") tse.displayError(e) exitStatus = e.exitCode else: msg = None sys.stderr.write(traceback.format_exc()) exitStatus = tse.INVALID_ERROR_CODE if msg == tse.NO_ERROR: sys.stdout.write(msg + '\n') elif msg is not None: sys.stderr.write(msg + '\n') # Return (exitStatus) sys.exit(exitStatus)
def Wrapper(self): """ Defines and invokes application independent exception handlers as appropriate to control exit codes and messages. """ # Verify user accessibility of one library known to be in hierarchy. try: preImportDevices = {"stdout": sys.stdout, "stderr": sys.stderr, " stdin": sys.stdin} if DEBUG: msg = "tsCommandLineEnv: preImportDevices=%s" % preImportDevices self.logger.debug(msg) except Exception as preImportDevicesError: msg = "tsCommandLineEnv: %s" % preImportDevicesError raise tse.ProgramException(tse.APPLICATION_TRAP, msg) # Remember original stdout and stderr _stdout = sys.stdout _stderr = sys.stderr # ------------------------------------------------------------------ exitStatus = tse.NONERROR_ERROR_CODE msg = tse.NO_ERROR try: self.runTimeEntryPoint() self.guiModeLauncher() except tse.UserInterfaceException as userErrorCode: msg = "EXCEPTION: tsMultiFrameEnv.cliWrapper: " + 'userErrorCode="%s"' % str(userErrorCode) sys.stderr.write(msg) ## if isinstance(applicationError, tse.TsExceptions): ## self.runTimeEntryPoint() ## self.guiModeLauncher() ## msg = str(applicationError).replace("'", "") ## tse.displayError(applicationError) ## exitStatus = applicationError.exitCode except Exception as applicationError: if isinstance(applicationError, tse.TsExceptions): msg = str(applicationError).replace("'", "") tse.displayError(applicationError) exitStatus = applicationError.exitCode else: msg = None sys.stderr.write(traceback.format_exc()) exitStatus = tse.INVALID_ERROR_CODE if msg == tse.NO_ERROR: sys.stdout.write(msg) elif msg is not None: sys.stderr.write(msg) # Return (exitStatus) sys.exit(exitStatus)