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 diagnosticExceptionTest(): exceptionName = tse.DIAGNOSTIC_EXCEPTION for errorName in tse.DiagnosticException.errorNames: message = 'Test(%s, %s)' % (exceptionName, errorName) myLogger.debug('***** %s / %s *****' % (exceptionName, errorName)) try: raise tse.DiagnosticException(errorName, message) except tse.DiagnosticException, e1: tse.displayError(e1) except Exception, e1: sys.stderr.write('Unknown exception: %s' % e1)
_stdout = sys.stdout _stderr = sys.stderr _stderr.write("%s" % __header__) exitStatus = tse.NONERROR_ERROR_CODE msg = tse.NO_ERROR if isinstance(theTsWxImportError, tse.TsExceptions): exitStatus = theTsWxImportError.exitCode msg = "%s. [ExitCode #%d]" % (str(theTsWxImportError).replace("'", ""), exitStatus) if tracebackEnabled: _stderr.write("\n%s\n\n" % msg) tse.displayError(theTsWxImportError) elif isinstance(theTsWxImportError, ImportError): exitStatus = 128 # TBD - tse.INVALID_ERROR_CODE msg = "%s. %s. %s. [ExitCode #%d]" % ( tse.USER_INTERFACE_EXCEPTION, tse.CHARACTER_GRAPHICS_NOT_AVAILABLE, theTsWxImportError, exitStatus, ) if tracebackEnabled: _stderr.write("\n%s\n\n" % msg) _stderr.write(traceback.format_exc()) else:
## 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)
try: theApplication = cliAPP( header=__header__, mainTitleVersionDate=mainTitleVersionDate, title=__title__, version=__version__, date=__date__, logs=[]) theApplication.runMain() except Exception as e: if isinstance(e, tse.TsExceptions): msg = str(e) tse.displayError(e) exitStatus = e.exitCode else: msg = None _stderr.write(traceback.format_exc()) exitStatus = tse.INVALID_ERROR_CODE ## print __header__ # _stdout.write(__header__) if msg == tse.NO_ERROR: _stdout.write(msg + '\n') elif msg is not None: _stderr.write(msg.replace('"', '') + '\n')
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)
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, 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
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 print(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: if False and DEBUG: (args, options) = self.getLaunchSettings() print('\n\n\tCommandLineEnv.Wrapper') print('\n\n\targs=%s' % str(args)) print('\n\n\toptions=%s' % str(options)) ## self.runTimeEntryPoint(instantiationSettings=(args, options)) self.runTimeEntryPoint() 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)