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)
(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
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 = {}