def tsGetPlatformRunTimeEnvironment(self): ''' Build list of strings that describe the following standard runtime enviroment features: "Network Host", "Python Virtual Machine", "Host Operating System", "Host Central Processing Unit", "Process Parameters" with associated platform specific details. ''' theInfo = [] lines = __header__.split('\n') for line in lines: theInfo += [line] theBeginTitle = 'Begin Platform Run Time Environment' theEndTitle = 'End Platform Run Time Environment' theInfo += ['%s' % \ tsrpu.getSeparatorString(title=theBeginTitle, separatorCharacter='=', position=tsrpu.layout[ 'TitleCenter'])] theInfo += ['\n'] theInfo += [' Reported %s' % \ tsrpu.getDateAndTimeString(time.time())] self.tsGetNetworkIdentification(theInfo) self.tsGetHostCentralProcessingUnit(theInfo) self.tsGetHostOperatingSystem(theInfo) self.tsGetHostConsoleDisplaySize(theInfo) self.tsGetPythonPlatform(theInfo) self.tsGetJavaPlatform(theInfo) self.tsGetMacPlatform(theInfo) self.tsGetLinuxPlatform(theInfo) self.tsGetWindowsPlatform(theInfo) self.tsGetProcessParameters(theInfo) theInfo += ['%s' % \ tsrpu.getSeparatorString(title=theEndTitle, separatorCharacter='=', position=tsrpu.layout[ 'TitleCenter'])] return theInfo
def tsCreateScrollableRedirectionLog(self): ''' Return file instance used for scrollable redirected output. ''' # TBD - Begin prototype for Scrollable Redirection Window # Will need an application instance specific file name. theDirectory = os.getcwd() theWindowTitle = self.ts_Title theKeyWord = theWindowTitle.split(' ', 1) theNickName = theKeyWord[0].strip('_').title() theFileName = '%s-stdout' % theNickName if True: thePathName = os.path.join( tsLogger.TsLogger.defaultStandardOutputPath, '%s.log' % theFileName) else: thePathName = tsru.getNextPathName(theDirectory, theFileName) theLogFile = open(thePathName, 'w') theLogFileHeader = tsru.getSeparatorString( title='Begin %s on %s' % ( 'PRINT/STDOUT/STDERR log', tsru.getDateAndTimeString(time.time())), indent=0, position=tsru.layout['TitleIndent'], separatorCharacter='$', tab=4) theLogFile.write('%s\n\n' % theLogFileHeader) theLogFile.write('%s - Started logging to file "%s".\n\n' % ( tsru.getDateTimeString(time.time(), msec=True), thePathName)) # TBD - End prototype for Scrollable Redirection Window return (theLogFile)
'stderr': sys.stderr, ' stdin': sys.stdin} for theKey in list(fileStdioDevices.keys()): self.logger.debug( ' Saved %s %s' % ( theKey, fileStdioDevices[theKey])) except Exception, fileStdioDevicesError: msg = "tsWxApp: %s" % fileStdioDevicesError raise tse.ProgramException( tse.APPLICATION_TRAP, msg) theLogFileHeader = tsru.getSeparatorString( title='Begin %s on %s' % ( 'PRINT/STDOUT/STDERR log', tsru.getDateAndTimeString(time.time())), indent=0, position=tsru.layout['TitleIndent'], separatorCharacter='$', tab=4) self.stdioLog.write('%s\n\n' % theLogFileHeader) self.stdioLog.write('%s - Started logging to file "%s".\n\n' % ( tsru.getDateTimeString(time.time()), filename)) msg1 = 'Print statements and other standard output ' msg2 = 'will now be directed to this file.' self.stdioLog.write('%s\n' % (msg1 + msg2)) self.stdioLog.flush()
def RedirectStdio(self, filename=None): ''' Redirect sys.stdout and sys.stderr to a file or a popup window. ''' # Verify user accessibility of one library known to be in hierarchy. try: preRedirectStdioDevices = {'stdout': sys.stdout, 'stderr': sys.stderr, ' stdin': sys.stdin} for theKey in list(preRedirectStdioDevices.keys()): self.logger.debug( ' Saved %s %s' % ( theKey, preRedirectStdioDevices[theKey])) except Exception as preRedirectStdioDevicesError: msg = "tsWxApp: %s" % preRedirectStdioDevicesError raise tse.ProgramException( tse.APPLICATION_TRAP, msg) # Save configuration for future restoration by RestoreStdio. self.saveStdio = (sys.stdout, sys.stderr) if filename is None: # Redirect output to a window on the screen. # Capture redirected output to a default file for scrolling. # TBD - How can this support the ThemeToUse Timestamp feature? self.stdioWin = self.outputWindowClass(wx.ThemeToUse['Stdio']['Title']) sys.stdout = self.stdioWin sys.stderr = self.stdioWin try: windowStdioDevices = {'stdout': sys.stdout, 'stderr': sys.stderr, ' stdin': sys.stdin} for theKey in list(windowStdioDevices.keys()): self.logger.debug( ' Saved %s %s' % ( theKey, windowStdioDevices[theKey])) except Exception as windowStdioDevicesError: msg = "tsWxApp: %s" % windowStdioDevicesError raise tse.ProgramException( tse.APPLICATION_TRAP, msg) else: # Redirect output to the specified file. # Setting buffer size of 0 eliminates need for flushing. if wx.ThemeToUse['Stdio']['Timestamp']: self.stdioLog = tsCustomStdioFile(filename, 'w', 1) else: self.stdioLog = open(filename, 'w', 1) sys.stdout = self.stdioLog sys.stderr = self.stdioLog try: fileStdioDevices = {'stdout': sys.stdout, 'stderr': sys.stderr, ' stdin': sys.stdin} for theKey in list(fileStdioDevices.keys()): self.logger.debug( ' Saved %s %s' % ( theKey, fileStdioDevices[theKey])) except Exception as fileStdioDevicesError: msg = "tsWxApp: %s" % fileStdioDevicesError raise tse.ProgramException( tse.APPLICATION_TRAP, msg) theLogFileHeader = tsru.getSeparatorString( title='Begin %s on %s' % ( 'PRINT/STDOUT/STDERR log', tsru.getDateAndTimeString(time.time())), indent=0, position=tsru.layout['TitleIndent'], separatorCharacter='$', tab=4) self.stdioLog.write('%s\n\n' % theLogFileHeader) self.stdioLog.write('%s - Started logging to file "%s".\n\n' % ( tsru.getDateTimeString(time.time()), filename)) msg1 = 'Print statements and other standard output ' msg2 = 'will now be directed to this file.' self.stdioLog.write('%s\n' % (msg1 + msg2)) self.stdioLog.flush()