From: Serge Rehbinder Date: Wed, 8 Jun 2016 07:39:39 +0000 (+0200) Subject: Add the shell command X-Git-Tag: 5.0.0a0~29 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2d2c73f8d815b699181237592c829c4e00d93a9f;p=tools%2Fsat.git Add the shell command --- diff --git a/commands/shell.py b/commands/shell.py new file mode 100644 index 0000000..47a8179 --- /dev/null +++ b/commands/shell.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python +#-*- coding:utf-8 -*- +# Copyright (C) 2010-2012 CEA/DEN +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +import subprocess + +import src + +# Define all possible option for the make command : sat make +parser = src.options.Options() +parser.add_option('s', 'sat', 'string', 'sat', + _('The salomeTools path to use for the command.')) +parser.add_option('c', 'command', 'string', 'command', + _('The shell command to execute.'), "") + +def description(): + '''method that is called when salomeTools is called with --help option. + + :return: The text to display for the shell command description. + :rtype: str + ''' + return _("Executes the shell command passed as argument") + +def run(args, runner, logger): + '''method that is called when salomeTools is called with shell parameter. + ''' + + # Parse the options + (options, args) = parser.parse_args(args) + + res = subprocess.call(options.command, + shell=True, + stdout=logger.logTxtFile, + stderr=subprocess.STDOUT) + + # Format the result to be 0 (success) or 1 (fail) + if res != 0: + res = 1 + + return res \ No newline at end of file diff --git a/complete_sat.sh b/complete_sat.sh index a10a0d9..9dd140b 100755 --- a/complete_sat.sh +++ b/complete_sat.sh @@ -80,7 +80,7 @@ _salomeTools_complete() # first argument => show available commands if [[ ${argc} == 1 ]] then - opts="config log testcommand source patch prepare environ clean configure make makeinstall compile launcher run jobs --help" + opts="config log testcommand source patch prepare environ clean configure make makeinstall compile launcher run jobs shell --help" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 fi @@ -194,6 +194,11 @@ _salomeTools_complete() COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; + shell) + opts="--command --sat" + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 + ;; *) return 0 ;; esac diff --git a/salomeTools.py b/salomeTools.py index 4efb2d0..4049ed2 100755 --- a/salomeTools.py +++ b/salomeTools.py @@ -151,10 +151,21 @@ class Sat(object): gettext.install('salomeTools', os.path.join(satdir, 'src', 'i18n')) # Get the arguments in a list and remove the empty elements - argv = args.split(" ") - if argv != ['']: - while "" in argv: argv.remove("") - + argv_0 = args.split(" ") + if argv_0 != ['']: + while "" in argv_0: argv_0.remove("") + + # Format the argv list in order to prevent strings + # that contain a blank to be separated + argv = [] + elem_old = "" + for elem in argv_0: + if argv == [] or elem_old.startswith("-") or elem.startswith("-"): + argv.append(elem) + else: + argv[-1] += " " + elem + elem_old = elem + # if it is provided by the command line, get the application appliToLoad = None if argv != [''] and argv[0][0] != "-":