Salome HOME
Add the shell command
authorSerge Rehbinder <serge.rehbinder@cea.fr>
Wed, 8 Jun 2016 07:39:39 +0000 (09:39 +0200)
committerSerge Rehbinder <serge.rehbinder@cea.fr>
Wed, 8 Jun 2016 07:39:39 +0000 (09:39 +0200)
commands/shell.py [new file with mode: 0644]
complete_sat.sh
salomeTools.py

diff --git a/commands/shell.py b/commands/shell.py
new file mode 100644 (file)
index 0000000..47a8179
--- /dev/null
@@ -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 <options>
+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
index a10a0d993fc9cec2531435de53c97db839ddc291..9dd140b434f298489becd209b18dea78df8a25f0 100755 (executable)
@@ -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
     
index 4efb2d0d8041a1ff8f4490651118e6b04f1c8ecc..4049ed2436995460ea1e0d14b2a4694afc56945f 100755 (executable)
@@ -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] != "-":