# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import os
+import sys
+import traceback
+import tempfile
import src
# 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('', 'name', 'string', 'job',
- _('The job name from which to execute commands.'), "")
+ _('Mandatory: The job name from which to execute commands.'), "")
def description():
'''method that is called when salomeTools is called with --help option.
:rtype: str
'''
return _("Executes the commands of the job defined"
- " in the jobs configuration file")
+ " in the jobs configuration file\n\nexample:\nsat 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:
src.printcolors.printcLabel(command) + " ", 3)
logger.write("." * (len_max_command - len(command)) + " ", 3)
logger.flush()
- # Execute the command
- code = sat_command(end_cmd,
- batch = True,
- verbose = 0,
- logger_add_link = logger)
+
+ error = ""
+ stack = ""
+ try:
+ # Execute the command
+ code = sat_command(end_cmd,
+ batch = True,
+ verbose = 0,
+ logger_add_link = logger)
+ except Exception as e:
+ code = 1
+ # Get error
+ error = str(e)
+ # get stack
+ __, __, exc_traceback = sys.exc_info()
+ fp = tempfile.TemporaryFile()
+ traceback.print_tb(exc_traceback, file=fp)
+ fp.seek(0)
+ stack = fp.read()
+ logger.add_link(_("Dead Link"),
+ sat_command_name,
+ code,
+ "ERROR: %s TRACEBACK: %s" % (error,
+ stack.replace('"',"'")))
+
# 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)
+ 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: