Salome HOME
sat jobs: get the remote log on the local machine. Cancel jobs that have a failing...
[tools/sat.git] / commands / shell.py
1 #!/usr/bin/env python
2 #-*- coding:utf-8 -*-
3 #  Copyright (C) 2010-2012  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 subprocess
20
21 import src
22
23 # Define all possible option for the make command :  sat make <options>
24 parser = src.options.Options()
25 parser.add_option('s', 'sat', 'string', 'sat',
26     _('The salomeTools path to use for the command.'))
27 parser.add_option('c', 'command', 'string', 'command',
28     _('The shell command to execute.'), "")
29
30 def description():
31     '''method that is called when salomeTools is called with --help option.
32     
33     :return: The text to display for the shell command description.
34     :rtype: str
35     '''
36     return _("Executes the shell command passed as argument")
37   
38 def run(args, runner, logger):
39     '''method that is called when salomeTools is called with shell parameter.
40     '''
41     
42     # Parse the options
43     (options, args) = parser.parse_args(args)
44       
45     res = subprocess.call(options.command,
46                           shell=True,
47                           stdout=logger.logTxtFile,
48                           stderr=subprocess.STDOUT)
49     
50     # Format the result to be 0 (success) or 1 (fail)
51     if res != 0:
52         res = 1
53     
54     return res