From ffb575fb87d39b96f6108dfaa479e59d0da1dae3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=A9dric=20Aguerre?= Date: Thu, 20 Jul 2017 17:33:01 +0200 Subject: [PATCH] Return error codes Conflicts: bin/runConsole.py bin/runSession.py bin/salomeContext.py --- bin/runConsole.py | 7 ++++--- bin/runSession.py | 20 +++++++++++++------- bin/salomeContext.py | 19 ++++++++++++------- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/bin/runConsole.py b/bin/runConsole.py index e8a9a60d9..1788b206c 100644 --- a/bin/runConsole.py +++ b/bin/runConsole.py @@ -61,7 +61,7 @@ For example: (options, args) = parser.parse_args(args) except Exception as e: print(e) - return + return {}, [] return options, args # @@ -197,7 +197,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, @@ -218,7 +218,8 @@ def connect(args=None, env=None): cmdDump=pickle.dumps(cmd,protocol=0) cmdString=cmdDump.decode() proc = subprocess.Popen(['python', os.path.join(absoluteAppliPath,"bin","salome","runConsole.py"), cmdString], 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 2f670b1de..9280c09d5 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 as 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 8a78e1442..0d12eca56 100644 --- a/bin/salomeContext.py +++ b/bin/salomeContext.py @@ -321,6 +321,7 @@ class SalomeContext: import runSalome runSalome.runSalome() + return 0 # def _setContext(self, args=None): @@ -330,7 +331,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("***") @@ -340,7 +341,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): @@ -375,7 +377,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 @@ -385,7 +387,7 @@ class SalomeContext: p = Process(target = killMyPort, args=(port,)) p.start() p.join() - pass + return 0 # def _killAll(self, unused=None): @@ -407,6 +409,7 @@ class SalomeContext: from killSalome import killAllPorts killAllPorts() pass + return 0 # def _runTests(self, args=None): @@ -468,7 +471,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 @@ -500,7 +503,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): @@ -510,7 +515,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: -- 2.39.2