From: Cédric Aguerre Date: Thu, 20 Jul 2017 15:33:01 +0000 (+0200) Subject: Return error codes X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ff60f6ba30a5174debe02bfce2f278fe7e7fc7d8;p=modules%2Fkernel.git Return error codes --- diff --git a/bin/runConsole.py b/bin/runConsole.py index 51f9fe2ba..fe62b6895 100644 --- a/bin/runConsole.py +++ b/bin/runConsole.py @@ -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__": diff --git a/bin/runSession.py b/bin/runSession.py index c83ef01a1..b96ecc801 100644 --- a/bin/runSession.py +++ b/bin/runSession.py @@ -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 # diff --git a/bin/salomeContext.py b/bin/salomeContext.py index bff6c5ba2..5c1f2ad0a 100644 --- a/bin/salomeContext.py +++ b/bin/salomeContext.py @@ -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 " - 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 " - return + return 1 appliPath = os.getenv("ABSOLUTE_APPLI_PATH") if not appliPath: