Salome HOME
sat job: add a red broken link when a command crashs
[tools/sat.git] / commands / job.py
index 0b7ed6db0bd741c9455a2dc90cccdf299e0a2143..b3aa9533ec5dae5738b96c57a5f77a323aae531e 100644 (file)
@@ -17,6 +17,9 @@
 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 
 import os
+import sys
+import traceback
+import tempfile
 
 import src
 
@@ -125,6 +128,7 @@ def run(args, runner, logger):
         logger.flush()
         
         error = ""
+        stack = ""
         try:
             # Execute the command
             code = sat_command(end_cmd,
@@ -133,8 +137,20 @@ def run(args, runner, logger):
                                logger_add_link = logger)
         except Exception as e:
             code = 1
+            # Get error
             error = str(e)
-
+            # get stack
+            __, __, exc_traceback = sys.exc_info()
+            fp = tempfile.TemporaryFile()
+            traceback.print_tb(exc_traceback, file=fp)
+            fp.seek(0)
+            stack = fp.read()
+            logger.add_link(_("Dead Link"),
+                            sat_command_name,
+                            code,
+                            "ERROR: %s TRACEBACK: %s" % (error,
+                                                    stack.replace('"',"'")))
+            
         # Print the status of the command
         if code == 0:
             nb_pass += 1
@@ -143,6 +159,8 @@ def run(args, runner, logger):
             res = 1
             logger.write('%s %s\n' % (src.printcolors.printc(src.KO_STATUS),
                                       error), 3)
+            if len(stack) > 0:
+                logger.write('stack: %s\n' % stack, 3)
     
     # Print the final state
     if res == 0: