Salome HOME
Add the job command
[tools/sat.git] / salomeTools.py
index c2f1f6e6d849c6d7286e675a52a7314c1af59498..e384fc4d972ec654d894ae630feaad0e8411c602 100755 (executable)
@@ -79,6 +79,8 @@ parser.add_option('v', 'verbose', 'int', "output_verbose_level",
                   _("change output verbose level (default is 3)."))
 parser.add_option('b', 'batch', 'boolean', "batch", 
                   _("batch mode (no question)."))
+parser.add_option('t', 'all_in_terminal', 'boolean', "all_in_terminal", 
+                  _("All traces in the terminal (for example compilation logs)."))
 
 class Sat(object):
     '''The main class that stores all the commands of salomeTools
@@ -139,7 +141,7 @@ class Sat(object):
             (file_, pathname, description) = imp.find_module(nameCmd, [dirPath])
             module = imp.load_module(nameCmd, file_, pathname, description)
             
-            def run_command(args='', logger=None, batch = False, verbose = -1):
+            def run_command(args='', batch = False, verbose = -1, logger_add_link = None):
                 '''The function that will load the configuration (all pyconf)
                 and return the function run of the command corresponding to module
                 
@@ -149,16 +151,27 @@ class Sat(object):
                 gettext.install('salomeTools', os.path.join(satdir, 'src', 'i18n'))
                 
                 # Get the arguments in a list and remove the empty elements
-                argv = args.split(" ")
-                if argv != ['']:
-                    while "" in argv: argv.remove("")
-                               
+                argv_0 = args.split(" ")
+                if argv_0 != ['']:
+                    while "" in argv_0: argv_0.remove("")
+                
+                # Format the argv list in order to prevent strings 
+                # that contain a blank to be separated
+                argv = []
+                elem_old = ""
+                for elem in argv_0:
+                    if argv == [] or elem_old.startswith("-") or elem.startswith("-"):
+                        argv.append(elem)
+                    else:
+                        argv[-1] += " " + elem
+                    elem_old = elem
+                           
                 # if it is provided by the command line, get the application
                 appliToLoad = None
                 if argv != [''] and argv[0][0] != "-":
                     appliToLoad = argv[0].rstrip('*')
                     argv = argv[1:]
-                
+   
                 # read the configuration from all the pyconf files    
                 cfgManager = config.ConfigManager()
                 self.cfg = cfgManager.get_config(datadir=self.datadir, 
@@ -183,13 +196,11 @@ class Sat(object):
                     self.cfg.USER.output_verbose_level = 0
                 silent = (self.cfg.USER.output_verbose_level == 0)
 
-                # create log file, unless the command is called 
-                # with a logger as parameter
+                # create log file
                 logger_command = src.logger.Logger(self.cfg, 
-                                                   silent_sysstd=silent)
-                if logger:
-                    logger_command = logger
-                
+                                                   silent_sysstd=silent,
+                                                   all_in_terminal=self.options.all_in_terminal)
+                               
                 try:
                     # Execute the hooks (if there is any) 
                     # and run method of the command
@@ -197,6 +208,10 @@ class Sat(object):
                     res = __module__.run(argv, self, logger_command)
                     self.run_hook(__nameCmd__, C_POST_HOOK, logger_command)
                     
+                    # set res if it is not set in the command
+                    if res is None:
+                        res = 0
+                    
                     # come back in the original batch mode if 
                     # batch argument was called
                     if batch:
@@ -207,8 +222,6 @@ class Sat(object):
                     if verbose > -1:
                         self.options.__setattr__("output_verbose_level", 
                                                  verbose_save)
-                        
-                finally:
                     # put final attributes in xml log file 
                     # (end time, total time, ...) and write it
                     launchedCommand = ' '.join([self.cfg.VARS.salometoolsway +
@@ -216,7 +229,32 @@ class Sat(object):
                                                 'sat',
                                                 __nameCmd__, 
                                                 args])
-                    logger_command.end_write({"launchedCommand" : launchedCommand})
+                    launchedCommand = launchedCommand.replace('"', "'")
+                    
+                    # Add a link to the parent command      
+                    if logger_add_link is not None:
+                        xmlLinks = logger_add_link.xmlFile.xmlroot.find(
+                                                                    "Links")
+                        src.xmlManager.add_simple_node(xmlLinks, 
+                                                       "link", 
+                                            text = logger_command.logFileName,
+                                            attrib = {"command" : __nameCmd__,
+                                                      "passed" : res,
+                                        "launchedCommand" : launchedCommand})
+                        logger_add_link.l_logFiles +=    logger_command.l_logFiles
+
+                finally:
+                    launchedCommand = ' '.join([self.cfg.VARS.salometoolsway +
+                                                os.path.sep +
+                                                'sat',
+                                                __nameCmd__, 
+                                                args])
+                    launchedCommand = launchedCommand.replace('"', "'")
+                    
+                    # Put the final attributes corresponding to end time and
+                    # Write the file to the hard drive
+                    logger_command.end_write(
+                                        {"launchedCommand" : launchedCommand})
                 
                 return res