]> SALOME platform Git repositories - modules/yacs.git/commitdiff
Salome HOME
Return error codes
authorCédric Aguerre <cedric.aguerre@edf.fr>
Thu, 20 Jul 2017 15:33:01 +0000 (17:33 +0200)
committerCédric Aguerre <cedric.aguerre@edf.fr>
Thu, 20 Jul 2017 15:34:20 +0000 (17:34 +0200)
bin/runConsole.py
bin/runSession.py
bin/salomeContext.py

index 51f9fe2bae9ea547f950519c7bd0fbf8a07897bc..fe62b6895225289254a9c5fb1e1dd7c95bdffefe 100644 (file)
@@ -62,7 +62,7 @@ For example:
     (options, args) = parser.parse_args(args)
   except Exception, e:
     print e
-    return
+    return {}, []
 
   return options, args
 #
@@ -198,7 +198,7 @@ def connect(args=None, env=None):
   options, args = __parse_args(args)
   host, port, filename = __get_running_session(options.port)
   if not port:
-    return 0
+    return 1
 
   cmd = [
     "os.environ['OMNIORB_CONFIG'] = '%s'"%filename,
@@ -215,7 +215,8 @@ def connect(args=None, env=None):
     absoluteAppliPath = os.getenv('ABSOLUTE_APPLI_PATH','')
     env_copy = os.environ.copy()
     proc = subprocess.Popen(['python', os.path.join(absoluteAppliPath,"bin","salome","runConsole.py"), pickle.dumps(cmd)], shell=False, close_fds=True, env=env_copy)
-    return proc.communicate()
+    proc.communicate()
+    return proc.returncode
 #
 
 if __name__ == "__main__":
index e06150138c4652ae3a0dc196398279837bf2aa55..761e5d023ed24e32805a47f4f7d04da6b224eee0 100644 (file)
@@ -1,5 +1,5 @@
 #  -*- coding: iso-8859-1 -*-
-# Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
+# Copyright (C) 2007-2017  CEA/DEN, EDF R&D, OPEN CASCADE
 #
 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -123,7 +123,7 @@ User "myself" connects to remotemachine to run the script concatenate.py in
     (options, args) = parser.parse_args(short_args)
   except Exception, e:
     print e
-    return
+    return None, []
 
   port = options.port
   host = options.host
@@ -215,7 +215,7 @@ def __runLocalSession(command):
           sys.stderr.write("".join(errmsg))
         sys.exit(1)
 
-    return ("".join(outmsg), "".join(errmsg))
+    return 0
   else:
     absoluteAppliPath = os.getenv('ABSOLUTE_APPLI_PATH','')
     if sys.platform == "win32":
@@ -223,7 +223,8 @@ def __runLocalSession(command):
     else:
       cmd = ["/bin/bash",  "--rcfile", absoluteAppliPath + "/.bashrc" ]
     proc = subprocess.Popen(cmd, shell=False, close_fds=True)
-    return proc.communicate()
+    proc.communicate()
+    return proc.returncode
 #
 
 def __copyFiles(user, machine, script, infiles, outfiles):
@@ -283,10 +284,10 @@ def __copyFiles(user, machine, script, infiles, outfiles):
 def __runRemoteSession(sa_obj, params):
   if not params.user:
     print "ERROR: The user login on remote machine MUST be given."
-    return
+    return 1
   if not params.directory:
     print "ERROR: The remote directory MUST be given."
-    return
+    return 1
 
   # sa_obj.script may be 'python script.py' --> only process .py file
   header = " ".join(sa_obj.script.split()[:-1])
@@ -318,6 +319,7 @@ def __runRemoteSession(sa_obj, params):
   os.system(command)
   os.remove(tmp_script)
 
+  return 0
 #
 
 def runSession(params, args):
@@ -328,6 +330,10 @@ def runSession(params, args):
     return __runLocalSession(command)
 
   elif params.mode == "remote":
+    any_error = 0
     for sa_obj in scriptArgs:
-      __runRemoteSession(sa_obj, params)
+      ok = __runRemoteSession(sa_obj, params)
+      if not ok:
+        any_error = 1
+    return any_error
 #
index 69116a8c8be3abf4ea8c5aadb9a715a97ce65e8d..f6c367e6a721b387e40a1dd6133845636407e7c9 100644 (file)
@@ -319,6 +319,7 @@ class SalomeContext:
 
     import runSalome
     runSalome.runSalome()
+    return 0
   #
 
   def _setContext(self, args=None):
@@ -328,7 +329,7 @@ class SalomeContext:
       print "*** SALOME context has already been set."
       print "*** Enter 'exit' (only once!) to leave SALOME context."
       print "***"
-      return
+      return 0
 
     os.environ["SALOME_CONTEXT_SET"] = "yes"
     print "***"
@@ -338,7 +339,8 @@ class SalomeContext:
 
     cmd = ["/bin/bash"]
     proc = subprocess.Popen(cmd, shell=False, close_fds=True)
-    return proc.communicate()
+    proc.communicate()
+    return proc.returncode()
   #
 
   def _runSession(self, args=None):
@@ -373,7 +375,7 @@ class SalomeContext:
     ports = args
     if not ports:
       print "Port number(s) not provided to command: salome kill <port(s)>"
-      return
+      return 1
 
     from multiprocessing import Process
     from killSalomeWithPort import killMyPort
@@ -383,7 +385,7 @@ class SalomeContext:
         p = Process(target = killMyPort, args=(port,))
         p.start()
         p.join()
-    pass
+    return 0
   #
 
   def _killAll(self, unused=None):
@@ -405,6 +407,7 @@ class SalomeContext:
       from killSalome import killAllPorts
       killAllPorts()
       pass
+    return 0
   #
 
   def _runTests(self, args=None):
@@ -466,7 +469,7 @@ Available options are:
 
     if "-h" in args or "--help" in args:
       print usage + epilog
-      return
+      return 0
 
     if "-p" in args or "--ports" in args:
       import PortManager
@@ -498,7 +501,9 @@ Available options are:
 
     if "-v" in args or "--version" in args:
       print "Running with python", platform.python_version()
-      self._runAppli(["--version"])
+      return self._runAppli(["--version"])
+
+    return 0
   #
 
   def _showDoc(self, args=None):
@@ -508,7 +513,7 @@ Available options are:
     modules = args
     if not modules:
       print "Module(s) not provided to command: salome doc <module(s)>"
-      return
+      return 1
 
     appliPath = os.getenv("ABSOLUTE_APPLI_PATH")
     if not appliPath: