Salome HOME
associate the logging functionnality to each commands and not to the global class Sat
[tools/sat.git] / salomeTools.py
index 742bc70bf919f63be8f0049a3a9c92bad063fac2..30a3697146d487234b7305c021d25b05f12b5a2c 100755 (executable)
@@ -90,7 +90,6 @@ class Sat(object):
         self.cfg = None # the config that will be read using pyconf module
         self.options = options # the options passed to salomeTools
         self.dataDir = dataDir # default value will be <salomeTools root>/data
         self.cfg = None # the config that will be read using pyconf module
         self.options = options # the options passed to salomeTools
         self.dataDir = dataDir # default value will be <salomeTools root>/data
-        self.logger = None
         # set the commands by calling the dedicated function
         self.__setCommands__(cmdsdir)
         
         # set the commands by calling the dedicated function
         self.__setCommands__(cmdsdir)
         
@@ -124,7 +123,7 @@ class Sat(object):
             (file_, pathname, description) = imp.find_module(nameCmd, [dirPath])
             module = imp.load_module(nameCmd, file_, pathname, description)
             
             (file_, pathname, description) = imp.find_module(nameCmd, [dirPath])
             module = imp.load_module(nameCmd, file_, pathname, description)
             
-            def run_command(args=''):
+            def run_command(args='', logger=None):
                 '''The function that will load the configuration (all pyconf)
                 and return the function run of the command corresponding to module
                 
                 '''The function that will load the configuration (all pyconf)
                 and return the function run of the command corresponding to module
                 
@@ -138,22 +137,28 @@ class Sat(object):
                     appliToLoad = argv[0].rstrip('*')
                     argv = argv[1:]
                 
                     appliToLoad = argv[0].rstrip('*')
                     argv = argv[1:]
                 
-                # Read the config if it is not already done
-                if not self.cfg:
-                    # read the configuration from all the pyconf files    
-                    cfgManager = config.ConfigManager()
-                    self.cfg = cfgManager.getConfig(dataDir=self.dataDir, application=appliToLoad, options=self.options, command=__nameCmd__)
+                # read the configuration from all the pyconf files    
+                cfgManager = config.ConfigManager()
+                self.cfg = cfgManager.getConfig(dataDir=self.dataDir, application=appliToLoad, options=self.options, command=__nameCmd__)
                     
                     
-                    # set output level
-                    if self.options.output_level:
-                        self.cfg.USER.output_level = self.options.output_level
-                    if self.cfg.USER.output_level < 1:
-                        self.cfg.USER.output_level = 1
+                # set output level
+                if self.options.output_level:
+                    self.cfg.USER.output_level = self.options.output_level
+                if self.cfg.USER.output_level < 1:
+                    self.cfg.USER.output_level = 1
 
 
-                    # create log file
-                    self.logger = src.logger.Logger(self.cfg, silent_sysstd=self.options.silent)
+                # create log file, unless the command is called with a logger as parameter
+                logger_command = src.logger.Logger(self.cfg, silent_sysstd=self.options.silent)
+                if logger:
+                    logger_command = logger
                 
                 
-                return __module__.run(argv, self)
+                # Execute the run method of the command
+                res = __module__.run(argv, self, logger_command)
+                
+                # put final attributes in xml log file (end time, total time, ...) and write it
+                logger_command.endWrite()
+                
+                return res
 
             # Make sure that run_command will be redefined at each iteration of the loop
             globals_up = {}
 
             # Make sure that run_command will be redefined at each iteration of the loop
             globals_up = {}