Salome HOME
decode pip version
[tools/sat.git] / commands / shell.py
index 6801fcac74a7b9879f6cb9f70fa5257c07c9ef41..c2139755c3b373d66b2a1ab64b1a4be4cc03dee2 100644 (file)
@@ -20,10 +20,10 @@ import subprocess
 
 import src
 
-# Define all possible option for the make command :  sat make <options>
+# Define all possible option for the shell command :  sat shell <options>
 parser = src.options.Options()
 parser.add_option('c', 'command', 'string', 'command',
-    _('The shell command to execute.'), "")
+    _('Mandatory: The shell command to execute.'), "")
 
 def description():
     '''method that is called when salomeTools is called with --help option.
@@ -31,7 +31,11 @@ def description():
     :return: The text to display for the shell command description.
     :rtype: str
     '''
-    return _("Executes the shell command passed as argument")
+    return _("""\
+The shell command executes the shell commands passed as argument.
+
+example:
+>> sat shell --command "ls -l /tmp" """)
   
 def run(args, runner, logger):
     '''method that is called when salomeTools is called with shell parameter.
@@ -39,14 +43,30 @@ def run(args, runner, logger):
     
     # Parse the options
     (options, args) = parser.parse_args(args)
-      
+
+    # Make sure the command option has been called
+    if not options.command:
+        message = _("The option --command is required\n")      
+        logger.write(src.printcolors.printcError(message))
+        return 1
+    
+    # Print the input command
+    msg = _("Command to execute:\n%s\nExecution ... " % options.command)
+    logger.write(msg, 3)
+    
+    # Call the input command
     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
+        logger.write(src.printcolors.printc("KO"), 3)
+    else:
+        logger.write(src.printcolors.printc("OK"), 3)
+    
+    logger.write("\n",3)
     
     return res
\ No newline at end of file