Salome HOME
Improve help of each command
[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
25 def description():
26     '''method that is called when salomeTools is called with --help option.
27     
28     :return: The text to display for the run command description.
29     :rtype: str
30     '''
31     return _("This command runs the application launcher"
32              " with the given arguments.\n\nexample:\nsat run SALOME-master")
33
34 def run(args, runner, logger):
35     '''method that is called when salomeTools is called with run parameter.
36     '''
37
38     # check for product
39     src.check_config_has_application(runner.cfg)
40
41     # check for profile
42     src.check_config_has_profile(runner.cfg)
43
44     # Determine launcher path 
45     launcher_name = runner.cfg.APPLICATION.profile.launcher_name
46     launcher_dir = runner.cfg.APPLICATION.workdir
47     
48     # Check the launcher existence
49     if launcher_name not in  os.listdir(launcher_dir):
50         profile_name = runner.cfg.APPLICATION.profile.module
51         profile_install_dir = src.product.get_product_config(runner.cfg,
52                                                     profile_name).install_dir
53         launcher_dir = os.path.join(profile_install_dir, 'bin', 'salome')
54           
55     launcher_path = os.path.join(launcher_dir, launcher_name)
56     launcher_path = os.path.abspath(launcher_path)
57
58     if not os.path.exists(launcher_path):
59         message = _("The launcher at path %s is missing.\nDid you run the"
60                     " command 'sat launcher' ?\n") % launcher_path
61         raise src.SatException(message)
62
63     # Determine the command to launch (add the additional arguments)
64     command = launcher_path + " " + " ".join(args)
65
66     # Print the command
67     src.printcolors.print_value(logger, _("Executed command"), command, 2)
68     logger.write(_("Launching ...\n"))
69     logger.flush()
70     
71     # Run the launcher
72     subprocess.call(command,
73                     shell=True,
74                     stdout=logger.logTxtFile,
75                     stderr=subprocess.STDOUT)
76     
77     # Display information : how to get the logs
78     messageFirstPart = _("\nEnd of execution. To see the traces, "
79                          "please tap the following command :\n")
80     messageSecondPart = src.printcolors.printcLabel(
81                                             runner.cfg.VARS.salometoolsway +
82                                             os.sep +
83                                             "sat log " +
84                                             runner.cfg.VARS.application + "\n")
85     logger.write("  %s\n" %(messageFirstPart + messageSecondPart), 2)
86     
87     return 0