Salome HOME
Merge branch 'nct/jan21' of https://codev-tuleap.cea.fr/plugins/git/salome/sat into...
[tools/sat.git] / commands / run.py
1 #!/usr/bin/env python
2 #-*- coding:utf-8 -*-
3 #  Copyright (C) 2010-2013  CEA/DEN
4 #
5 #  This library is free software; you can redistribute it and/or
6 #  modify it under the terms of the GNU Lesser General Public
7 #  License as published by the Free Software Foundation; either
8 #  version 2.1 of the License.
9 #
10 #  This library is distributed in the hope that it will be useful,
11 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 #  Lesser General Public License for more details.
14 #
15 #  You should have received a copy of the GNU Lesser General Public
16 #  License along with this library; if not, write to the Free Software
17 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18
19 import os
20 import subprocess
21
22 import src
23
24 # Define all possible option for log command :  sat run <options>
25 parser = src.options.Options()
26 # no option more than -h as generic default
27
28 def description():
29     '''method that is called when salomeTools is called with --help option.
30     
31     :return: The text to display for the run command description.
32     :rtype: str
33     '''
34     return _("""\
35 The run command runs the application launcher with the given arguments.
36
37 example:
38 >> sat run SALOME-master
39 """)
40
41 def run(args, runner, logger):
42     '''method that is called when salomeTools is called with run parameter.
43     '''
44
45     # check for product
46     src.check_config_has_application(runner.cfg)
47
48     # Determine launcher path 
49     launcher_name = src.get_launcher_name(runner.cfg)
50     launcher_dir = runner.cfg.APPLICATION.workdir
51     
52     # Check the launcher existence
53     if launcher_name not in  os.listdir(launcher_dir):
54         message = _("The launcher %s was not found in directory %s!\nDid you run the"
55                     " command 'sat launcher' ?\n") % (launcher_name, launcher_dir)
56         raise src.SatException(message)
57           
58     launcher_path = os.path.join(launcher_dir, launcher_name)
59
60     if not os.path.exists(launcher_path):
61         message = _("The launcher at path %s is missing.\nDid you run the"
62                     " command 'sat launcher' ?\n") % launcher_path
63         raise src.SatException(message)
64
65     # Determine the command to launch (add the additional arguments)
66     command = launcher_path + " " + " ".join(args)
67
68     # Print the command
69     src.printcolors.print_value(logger, _("Executed command"), command, 2)
70     logger.write(_("Launching ...\n"))
71     logger.flush()
72     
73     # Run the launcher
74     subprocess.call(command,
75                     shell=True,
76                     stdout=logger.logTxtFile,
77                     stderr=subprocess.STDOUT)
78     
79     # Display information : how to get the logs
80     messageFirstPart = _("\nEnd of execution. To see the traces, "
81                          "please tap the following command :\n")
82     messageSecondPart = src.printcolors.printcLabel(
83                                             runner.cfg.VARS.salometoolsway +
84                                             os.sep +
85                                             "sat log " +
86                                             runner.cfg.VARS.application + "\n")
87     logger.write("  %s\n" %(messageFirstPart + messageSecondPart), 2)
88     
89     return 0