Anonymous avatar Anonymous committed 90f8998

see ChangeLog

Comments (0)

Files changed (5)

+7-03-2006 Martin Woudstra
+	python/trferr.py: added catching of exception KeyboardInterrupt
+	python/trf.py: 
+	    - writing output to logfile
+	    - added 'exec' to last.<mytrf> file to avoid re-running problems 
+	      due to it being overwritten while being run.
+	python/athena_wrapper.py: 
+	    - removal of old commented-out code.
+	    - exit with 'UnknownException' if errorHandler does not handle error.
 6-03-2006 Martin Woudstra
 	Imported everything from PyJobTransforms
 	Moved examples to the respective domain packages
 # 'normal' path* and set* commands.
 cmtpath_pattern \
 	path_remove  PYTHONPATH "/$(trfs_installdir)" ; \
+	path_remove  PATH  "/$(trfs_installdir)" ; \
+	set_remove   JOBOPTSEARCHPATH "/$(trfs_installdir)/jobOptions"
+
+cmtpath_pattern \
 	path_prepend PYTHONPATH "$(CMTINSTALLAREA)/$(trfs_installdir)" ; \
-	path_remove  PATH  "/$(trfs_installdir)" ; \
 	path_prepend PATH "$(CMTINSTALLAREA)/$(trfs_installdir)" ; \
-	set_remove  JOBOPTSEARCHPATH "/$(trfs_installdir)" ; \
-	set_prepend JOBOPTSEARCHPATH ",$(CMTINSTALLAREA)/$(trfs_installdir)/jobOptions"
-
-
+	set_prepend  JOBOPTSEARCHPATH ",$(CMTINSTALLAREA)/$(trfs_installdir)/jobOptions"

python/athena_wrapper.py

 #
 except exceptions.Exception, e:
     trferr.errorHandler.handleAthenaException(e)
-##     args0 = e.args[0]
-##     argType0 = type(args0)
-##     # test for some known strings
-##     if argType0 == type(''):
-##         if args0.find('Failed to load DLL') != -1:
-##             # try to find the guilty one
-##             mess = ""
-##             dllRE = "^theApp.Dlls\s*[+]?="
-##             stack = find_in_stack( dllRE )
-##             if stack:
-##                 text = stack[TRACEBACK_TEXT]
-##                 dllNameRE = "([\w\.\-]+)"
-##                 subRE = "%s%s%s%s" % (dllRE,r"\s*\[\s*\"", dllNameRE, r"\"\s*\]")
-##                 #print 'subRE_stack=%s' % subRE
-##                 dll = re.sub( subRE, r"\1", text )
-##                 lib = 'lib%s.so' % (dll)
-##                 full_lib = find_library(lib)
-##                 mess = 'module %s can not be loaded' % (dll)
-##                 if not full_lib:
-##                     mess = ' because %s can not found in LD_LIBRARY_PATH' % (lib)
-##                 else:
-##                     lddOut = os.popen( 'echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH"; ldd %s' % (full_lib) )
-##                     missLibs = [ ]
-##                     subRE = "%s%s%s" % (r"^\s*",dllNameRE,r"\s+.*not found\s*.*$")
-##                     #print 'subRE_ldd=%s' % subRE
-##                     for line in lddOut:
-##                         if re.search( "not found", line ):
-##                             misLib = re.sub( subRE, r"\1", line )
-##                             missLibs.append( misLib )
-##                             if find_library(misLib):
-##                                 print "I find %s, but ldd does not..." % misLib
-##                         elif re.search("LD_LIBRARY_PATH=", line ):
-##                             print line
-                            
-##                     lddOut.close()
-##                     if len(missLibs) >= 1:
-##                         mess += ' because %s can not found in LD_LIBRARY_PATH' % \
-##                                 (', '.join(missLibs))
-                        
-                    
-##             trferr.exit( trferr.ATHENA_LOAD_DLL_ERROR, mess )
-
-##     # if I get here, it's an unknown exception
-##     trferr.exit( trferr.UNKNOWN_EXCEPTION_RAISED, '%s: %s' % (e.__class__.__name__ ,e.args) )
-
+    # if error handler does not handle error...
+    trferr.exit( trferr.UNKNOWN_EXCEPTION_RAISED, '%s: %s' % (e.__class__.__name__ ,e.args) )
 #
 # If all else fails...
 #
     _userOptsShort = "hd"
     _userOptsLong  = [ 'help', 'debug' ]
     _userOptsArg   = [ ''    , ''      ]
-    _userOptsHelp  = [
-        'Print detailed help',
-        'Print debug messages' ]
+    _userOptsHelp  = [ 'Print detailed help', 'Print debug messages' ]
     _runArgsName = 'runArgs'
     
     def __init__( self, version, authors, help, skeleton='default', name='default' ):
         self._logger = logging.getLogger( self._loggerName )
         self._logger.setLevel( logging.INFO )
         trferr.errorHandler.setLoggingContext( self._loggerName )
+        self._logfilename = name + '.log'
         # arguments
         self._filename = filename
         self._name    = name
         return self._skeleton
 
 
+    def logFilename(self):
+        return self._logfilename
+
+
     def runArgsFilename(self):
         return 'runargs.' + self._name + '.py'
 
     def writeLastCommand(self):
         lastname = 'last.' + self._name
         lastfile = open(lastname,'w')
-        lastfile.write( ' '.join(sys.argv) + os.linesep)
+        lastfile.write( 'exec ' + ' '.join(sys.argv) + os.linesep)
         lastfile.close()
         os.chmod(lastname, stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH )
 
         """Execute transformation. Can only be called after the arguments have been set"""
         #clean up old stuff
         Filename.remove(trferr.exitStatusFile)
+        Filename.remove(self.logFilename())
 
         try:
             # write the last command to file
             
             # run the athena job
             athena = os.path.join( trfenv.trfPath, 'athena_wrapper.py' )
-            syscommand = '%s %s %s' % ( athena, self.runArgsFilename(), self.skeletonFilename() )
+            syscommand = '%s %s %s 2>&1 | tee %s' % ( athena, self.runArgsFilename(), self.skeletonFilename(),
+                                                 self.logFilename() )
             self._logger.debug( 'Executing %s' % (syscommand) )
             status = os.system( syscommand ) >> 8 # status code is in upper byte of 16 bit word
             if status != 0:
 TRF_OK = 0
 ATHENA_FAILURE_ERROR = 1
 ATHENA_LOAD_DLL_ERROR = 3
+KEYBOARD_INTERRUPT = 4
 JOBOPTIONS_NOT_FOUND = 5
 JOBOPTIONS_PYTHON_ERROR = 6
 TRF_INPUTFILE_ERROR = 20
 messages = { TRF_OK : 'OK' ,
              ATHENA_FAILURE_ERROR     : 'AthenaExitWithFailure'  ,
              ATHENA_LOAD_DLL_ERROR    : 'AthenaFailLoadLibrary' ,
+             KEYBOARD_INTERRUPT       : 'KeyboardInterrupt' ,
              JOBOPTIONS_NOT_FOUND  : 'JobOptionsNotFound' ,
              JOBOPTIONS_PYTHON_ERROR : 'JobOptionsPythonError' ,
              TRF_INPUTFILE_ERROR   : 'TransformInputFileError'   ,
 
     def handleAthenaException(self,e):
         print "TransformErrorHandler.handleAthenaException(%s)..." % e.__class__.__name__
-        if isinstance(e,exceptions.Exception):
-            args0 = e.args[0]
-            argType0 = type(args0)
-            # test for some known strings
-            if argType0 == type(''):
-                if args0.find('Failed to load DLL') != -1:
-                    self.handleDllLoadError(e)
+        if isinstance(e,exceptions.KeyboardInterrupt):
+            self.handleKeyboardInterrupt(e)
+        elif isinstance(e,exceptions.Exception):
+            if hasattr(e,'args') and type(e.args) == type(list()) and e.args:
+                args0 = e.args[0]
+                argType0 = type(args0)
+                # test for some known strings
+                if argType0 == type(''):
+                    if args0.find('Failed to load DLL') != -1:
+                        self.handleDllLoadError(e)
 
-        # if I get here, it's an unknown exception
-        exit( UNKNOWN_EXCEPTION_RAISED, '%s: %s' % (e.__class__.__name__ ,e.args) )
-
+                        
+    def handleKeyboardInterrupt(self,e):
+        exit(KEYBOARD_INTERRUPT)
 
 
     def handleDllLoadError(self,e):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.