]> SALOME platform Git repositories - tools/sat.git/commitdiff
Salome HOME
associate the logging functionnality to each commands and not to the global class Sat
authorSerge Rehbinder <serge.rehbinder@cea.fr>
Wed, 10 Feb 2016 10:17:25 +0000 (11:17 +0100)
committerSerge Rehbinder <serge.rehbinder@cea.fr>
Wed, 10 Feb 2016 10:17:25 +0000 (11:17 +0100)
commands/config.py
commands/log.py
commands/testcommand.py
salomeTools.py

index 6b0f2cba3b4239a82042dc8e0ff90ec0f8064bd0..8de7fc60905bd8918d499bcc7d0f130c4a60d17c 100644 (file)
@@ -401,7 +401,7 @@ def description():
     return _("The config command allows manipulation and operation on config files.")
     
 
-def run(args, runner):
+def run(args, runner, logger):
     '''method that is called when salomeTools is called with config parameter.
     '''
     # Parse the options
@@ -412,9 +412,9 @@ def run(args, runner):
         if options.value == ".":
             # if argument is ".", print all the config
             for val in sorted(runner.cfg.keys()):
-                print_value(runner.cfg, val, True, runner.logger)
+                print_value(runner.cfg, val, True, logger)
         else:
-            print_value(runner.cfg, options.value, True, runner.logger, level=0, show_full_path=False)
+            print_value(runner.cfg, options.value, True, logger, level=0, show_full_path=False)
     
     # case : edit user pyconf file or application file
     elif options.edit:
@@ -468,7 +468,7 @@ def run(args, runner):
             
             # perform the copy
             shutil.copyfile(source_full_path, dest_file)
-            runner.logger.write(_("%s has been created.\n") % dest_file)
+            logger.write(_("%s has been created.\n") % dest_file)
     
     # case : display all the available pyconf applications
     elif options.list:
@@ -476,10 +476,10 @@ def run(args, runner):
         # search in all directories that can have pyconf applications
         for path in runner.cfg.SITE.config.configPath:
             # print a header
-            runner.logger.write("------ %s\n" % src.printcolors.printcHeader(path))
+            logger.write("------ %s\n" % src.printcolors.printcHeader(path))
 
             if not os.path.exists(path):
-                runner.logger.write(src.printcolors.printcError(_("Directory not found")) + "\n")
+                logger.write(src.printcolors.printcError(_("Directory not found")) + "\n")
             else:
                 for f in sorted(os.listdir(path)):
                     # ignore file that does not ends with .pyconf
@@ -490,10 +490,10 @@ def run(args, runner):
                     if appliname not in lproduct:
                         lproduct.append(appliname)
                         if path.startswith(runner.cfg.VARS.personalDir):
-                            runner.logger.write("%s*\n" % appliname)
+                            logger.write("%s*\n" % appliname)
                         else:
-                            runner.logger.write("%s\n" % appliname)
+                            logger.write("%s\n" % appliname)
                             
-            runner.logger.write("\n")
+            logger.write("\n")
     
     
\ No newline at end of file
index d09dbb60457db8970a10fa610605ee4c94ee9fdb..ee473e572b6422b229e728c25c128f4b849472e7 100644 (file)
@@ -39,7 +39,7 @@ def show_log_command_in_terminal(filePath, logger):
 def description():
     return _("Gives access to logs of salomeTools.")    
 
-def run(args, runner):
+def run(args, runner, logger):
     (options, args) = parser.parse_args(args)
 
     # get the log directory. If there is an application, it is in cfg.APPLICATION.out_dir, else in user directory
@@ -64,7 +64,7 @@ def run(args, runner):
             cmd = date_hour_cmd[2][:-len('.xml')]
             
             num = src.printcolors.printcLabel("%2d" % (nb_logs - index))
-            runner.logger.write("%s: %13s %s %s\n" % (num, cmd, date, hour), 1, False)
+            logger.write("%s: %13s %s %s\n" % (num, cmd, date, hour), 1, False)
             index += 1
         
         # ask the user
@@ -74,7 +74,7 @@ def run(args, runner):
     
             if x > 0:
                 index = len(lLogs) - int(x)
-                show_log_command_in_terminal(os.path.join(logDir, lLogs[index]), runner.logger)                
+                show_log_command_in_terminal(os.path.join(logDir, lLogs[index]), logger)                
                 x = 0
         
         return
index f2b0f808a0283a075bb33e15dd2a66edff422568..2dbd7e0753b505b3c2f96a67bcf83bdf30bb33a7 100644 (file)
@@ -12,10 +12,10 @@ def description():
     return _("Test d'une commande supplémentaire.")
     
 
-def run(args, runner):
+def run(args, runner, logger):
     (options, args) = parser.parse_args(args)
     if options.unique:
-        runner.logger.write('unique\n')
+        logger.write('unique\n')
     elif options.value:
         runner.cfg.VARS.user = 'TEST'
-        runner.config('-v ' + options.value)
+        runner.config('-v ' + options.value, logger)
index 711ee28f5b491d167a7209ffa191f6aed598deae..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.logger = None
         # 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)
             
-            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
                 
@@ -148,14 +147,16 @@ class Sat(object):
                 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
                 
                 # Execute the run method of the command
-                res = __module__.run(argv, self)
+                res = __module__.run(argv, self, logger_command)
                 
                 # put final attributes in xml log file (end time, total time, ...) and write it
-                self.logger.endWrite()
+                logger_command.endWrite()
                 
                 return res