From 8907858912a4ceb6358a1f6659e8b9dbd6ef4ef4 Mon Sep 17 00:00:00 2001 From: Serge Rehbinder Date: Wed, 30 Nov 2016 10:31:43 +0100 Subject: [PATCH] sat job: be able to pass global options to a specific command (sat -o ... command) --- commands/job.py | 20 ++++++++++++++++++-- commands/jobs.py | 3 ++- salomeTools.py | 40 ++++++++++++++++++++++++++++++++++++---- 3 files changed, 56 insertions(+), 7 deletions(-) diff --git a/commands/job.py b/commands/job.py index b3aa953..c15afdb 100644 --- a/commands/job.py +++ b/commands/job.py @@ -22,6 +22,7 @@ import traceback import tempfile import src +import salomeTools # Define all possible option for the make command : sat make parser = src.options.Options() @@ -111,15 +112,29 @@ def run(args, runner, logger): res = 0 nb_pass = 0 for command in commands: + specific_option = False # Determine if it is a sat command or a shell command cmd_exe = command.split(" ")[0] # first part if cmd_exe == "sat": - sat_command_name = command.split(" ")[1] - end_cmd = command.replace(cmd_exe + " " + sat_command_name, "") + # use the salomeTools parser to get the options of the command + sat_parser = salomeTools.parser + (options, argus) = sat_parser.parse_args(command.split(' ')[1:]) + # Verify if there is a changed option + for attr in dir(options): + if attr.startswith("__"): + continue + if options.__getattr__(attr) != None: + specific_option = True + sat_command_name = argus[0] + end_cmd = " ".join(argus[1:]) else: sat_command_name = "shell" end_cmd = "--command " + command + # Do not change the options if no option was called in the command + if not(specific_option): + options = None + # Get dynamically the command function to call sat_command = runner.__getattr__(sat_command_name) logger.write("Executing " + @@ -132,6 +147,7 @@ def run(args, runner, logger): try: # Execute the command code = sat_command(end_cmd, + options = options, batch = True, verbose = 0, logger_add_link = logger) diff --git a/commands/jobs.py b/commands/jobs.py index fb8497e..2fab295 100644 --- a/commands/jobs.py +++ b/commands/jobs.py @@ -1584,7 +1584,8 @@ def run(args, runner, logger): if not options.no_label: logger.write("------ %s\n" % src.printcolors.printcHeader(cfg_dir)) - + if not os.path.exists(cfg_dir): + continue for f in sorted(os.listdir(cfg_dir)): if not f.endswith('.pyconf'): continue diff --git a/salomeTools.py b/salomeTools.py index 5169f7a..069a324 100755 --- a/salomeTools.py +++ b/salomeTools.py @@ -157,7 +157,11 @@ class Sat(object): (file_, pathname, description) = imp.find_module(nameCmd, [dirPath]) module = imp.load_module(nameCmd, file_, pathname, description) - def run_command(args='', batch = False, verbose = -1, logger_add_link = None): + def run_command(args='', + options=None, + 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 @@ -187,14 +191,19 @@ class Sat(object): if argv != [''] and argv[0][0] != "-": appliToLoad = argv[0].rstrip('*') argv = argv[1:] - + + # Check if the global options of salomeTools have to be changed + if options: + options_save = self.options + self.options = options + # read the configuration from all the pyconf files cfgManager = config.ConfigManager() self.cfg = cfgManager.get_config(datadir=self.datadir, application=appliToLoad, options=self.options, command=__nameCmd__) - + # Set the verbose mode if called if verbose > -1: verbose_save = self.options.output_verbose_level @@ -254,6 +263,12 @@ class Sat(object): if res is None: res = 0 + # come back to the original global options + options_launched = "" + if options: + options_launched = get_text_from_options(self.options) + self.options = options_save + # come back in the original batch mode if # batch argument was called if batch: @@ -269,6 +284,7 @@ class Sat(object): launchedCommand = ' '.join([self.cfg.VARS.salometoolsway + os.path.sep + 'sat', + options_launched, __nameCmd__, args]) launchedCommand = launchedCommand.replace('"', "'") @@ -285,6 +301,7 @@ class Sat(object): launchedCommand = ' '.join([self.cfg.VARS.salometoolsway + os.path.sep + 'sat', + options_launched, __nameCmd__, args]) launchedCommand = launchedCommand.replace('"', "'") @@ -419,7 +436,22 @@ class Sat(object): (file_, pathname, description) = imp.find_module(module, [cmdsdir]) module = imp.load_module(module, file_, pathname, description) return module - + +def get_text_from_options(options): + text_options = "" + for attr in dir(options): + if attr.startswith("__"): + continue + if options.__getattr__(attr) != None: + option_contain = options.__getattr__(attr) + if type(option_contain)==type([]): + option_contain = ",".join(option_contain) + if type(option_contain)==type(True): + option_contain = "" + text_options+= "--%s %s " % (attr, option_contain) + return text_options + + def print_version(): '''prints salomeTools version (in src/internal_config/salomeTools.pyconf) ''' -- 2.39.2