import os
import src
+import src.salomeTools
# Define all possible option for the make command : sat make <options>
parser = src.options.Options()
parser.add_option('j', 'jobs_config', 'string', 'jobs_cfg',
- _('The name of the config file that contains'
+ _('Mandatory: The name of the config file that contains'
' the jobs configuration'))
-parser.add_option('', 'job', 'string', 'job',
- _('The job name from which to execute commands.'), "")
+parser.add_option('', 'name', 'string', 'job',
+ _('Mandatory: The job name from which to execute commands.'), "")
def description():
'''method that is called when salomeTools is called with --help option.
:return: The text to display for the job command description.
:rtype: str
'''
- return _("Executes the commands of the job defined"
- " in the jobs configuration file")
+ return _("""\
+The job command executes the commands of the job defined in the jobs configuration file
+
+example:
+>> sat job --jobs_config my_jobs --name my_job
+""")
def run(args, runner, logger):
'''method that is called when salomeTools is called with job parameter.
# Parse the options
(options, args) = parser.parse_args(args)
-
- jobs_cfg_files_dir = runner.cfg.SITE.jobs.config_path
-
- l_cfg_dir = [jobs_cfg_files_dir, os.path.join(runner.cfg.VARS.datadir, "jobs")]
-
- # Make sure the path to the jobs config files directory exists
- src.ensure_path_exists(jobs_cfg_files_dir)
+
+ l_cfg_dir = runner.cfg.PATHS.JOBPATH
# Make sure the jobs_config option has been called
if not options.jobs_cfg:
logger.write(src.printcolors.printcError(message))
return 1
+ # Make sure the name option has been called
+ if not options.job:
+ message = _("The option --name is required\n")
+ logger.write(src.printcolors.printcError(message))
+ return 1
+
# Find the file in the directories
found = False
for cfg_dir in l_cfg_dir:
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 = src.salomeTools.parser
+ input_parser = src.remove_item_from_list(command.split(' ')[1:], "")
+ (options, argus) = sat_parser.parse_args(input_parser)
+ # 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
-
- # Get dynamically the command function to call
+ 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 " +
src.printcolors.printcLabel(command) + " ", 3)
logger.write("." * (len_max_command - len(command)) + " ", 3)
logger.flush()
+
+ error = ""
+ stack = ""
# Execute the command
code = sat_command(end_cmd,
- batch = True,
- verbose = 0,
- logger_add_link = logger)
+ options = options,
+ batch = True,
+ verbose = 0,
+ logger_add_link = logger)
+
# Print the status of the command
if code == 0:
nb_pass += 1
logger.write('%s\n' % src.printcolors.printc(src.OK_STATUS), 3)
else:
- res = 1
- logger.write('%s\n' % src.printcolors.printc(src.KO_STATUS), 3)
+ if sat_command_name != "test":
+ res = 1
+ logger.write('%s %s\n' % (src.printcolors.printc(src.KO_STATUS),
+ error), 3)
+ if len(stack) > 0:
+ logger.write('stack: %s\n' % stack, 3)
# Print the final state
if res == 0: