From: Gilles DAVID Date: Tue, 18 Apr 2017 13:21:29 +0000 (+0200) Subject: Merge remote-tracking branch 'origin/V8_3_BR' into ngr/python3_dev X-Git-Tag: V9_0_0~25^2~10 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=df2f3847c7cecf6d51055cb5872105121a15bcb2;p=modules%2Fkernel.git Merge remote-tracking branch 'origin/V8_3_BR' into ngr/python3_dev Conflicts: bin/appliskel/salome_starter.py bin/appliskel/salome_tester/salome_test_driver.py bin/appliskel/salome_tester/salome_test_driver_gui.py bin/salomeContext.py --- df2f3847c7cecf6d51055cb5872105121a15bcb2 diff --cc bin/PortManager.py index c23c28d51,ced2ad296..f838a2ddf --- a/bin/PortManager.py +++ b/bin/PortManager.py @@@ -132,10 -142,10 +142,10 @@@ def getPort(preferedPort=None) __acquire_lock(lock) # read config - config = {'busy_ports':[]} + config = {} logger.debug("read configuration file") try: - with open(config_file, 'r') as f: + with open(config_file, 'rb') as f: config = pickle.load(f) except: logger.info("Problem loading PortManager file: %s"%config_file) @@@ -153,18 -167,16 +167,16 @@@ msg = "\n" msg += "Can't find a free port to launch omniNames\n" msg += "Try to kill the running servers and then launch SALOME again.\n" - raise RuntimeError, msg + raise RuntimeError(msg) logger.debug("Port %s seems to be busy"%str(port)) - if not port in config["busy_ports"]: - config["busy_ports"].append(port) port = port + 1 logger.debug("found free port: %s"%str(port)) - config["busy_ports"].append(port) + config[appli_path].append(port) # write config - logger.debug("write busy_ports: %s"%str(config["busy_ports"])) + logger.debug("write config: %s"%str(config)) try: - with open(config_file, 'w') as f: + with open(config_file, 'wb') as f: pickle.dump(config, f) except IOError: pass @@@ -189,27 -201,29 +201,29 @@@ def releasePort(port) __acquire_lock(lock) # read config - config = {'busy_ports':[]} + config = {} logger.debug("read configuration file") try: - with open(config_file, 'r') as f: + with open(config_file, 'rb') as f: config = pickle.load(f) except IOError: # empty file pass - logger.debug("load busy_ports: %s"%str(config["busy_ports"])) + logger.debug("load config: %s"%str(config)) + appli_path = os.getenv("ABSOLUTE_APPLI_PATH", "unknown") + try: + config[appli_path] + except KeyError: + config[appli_path] = [] # remove port from list - busy_ports = config["busy_ports"] - - if port in busy_ports: - busy_ports.remove(port) - config["busy_ports"] = busy_ports + ports_info = config[appli_path] + config[appli_path] = [x for x in ports_info if x != port] # write config - logger.debug("write busy_ports: %s"%str(config["busy_ports"])) + logger.debug("write config: %s"%str(config)) try: - with open(config_file, 'w') as f: + with open(config_file, 'wb') as f: pickle.dump(config, f) except IOError: pass @@@ -231,10 -244,10 +244,10 @@@ def getBusyPorts() __acquire_lock(lock) # read config - config = {'busy_ports':[]} + config = {} logger.debug("read configuration file") try: - with open(config_file, 'r') as f: + with open(config_file, 'rb') as f: config = pickle.load(f) except IOError: # empty file pass diff --cc bin/appliskel/salome_starter.py index 97f355e6b,795803d40..737b4c15d --- a/bin/appliskel/salome_starter.py +++ b/bin/appliskel/salome_starter.py @@@ -53,8 -53,8 +53,8 @@@ def initialize(launcherPath, launcherFi appliPath = __detectAppliPath(launcherPath, launcherFile) if appliPath is None: - print "ERROR: Unable to find application folder" + print("ERROR: Unable to find application folder") - sys.exit(0) + sys.exit(1) appliPath = os.path.relpath(appliPath, homePath) absoluteAppliPath = os.path.join(homePath, appliPath) diff --cc bin/appliskel/salome_tester/salome_test_driver.py index e4dbcd157,7b119d176..7eae08693 --- a/bin/appliskel/salome_tester/salome_test_driver.py +++ b/bin/appliskel/salome_tester/salome_test_driver.py @@@ -67,8 -53,8 +67,8 @@@ if __name__ == "__main__" # Add explicit call to python executable if a Python script is passed as # first argument if not args: - print "Invalid arguments for salome_test_driver.py. No command defined." + print("Invalid arguments for salome_test_driver.py. No command defined.") - exit(1) + sys.exit(1) _, ext = os.path.splitext(args[0]) if ext == ".py": test_and_args = [sys.executable] + args @@@ -104,10 -89,12 +104,12 @@@ import traceback traceback.print_exc() pass - - salome_instance.stop() + try: + salome_instance.stop() + except: + pass if sys.platform == 'win32': timer.cancel() - print "Exit test with status code:", res + print("Exit test with status code:", res) - exit(res) + sys.exit(res) # diff --cc bin/appliskel/salome_tester/salome_test_driver_gui.py index c6d856651,7ef53d33f..92a19d6b3 --- a/bin/appliskel/salome_tester/salome_test_driver_gui.py +++ b/bin/appliskel/salome_tester/salome_test_driver_gui.py @@@ -41,8 -41,8 +41,8 @@@ if __name__ == "__main__" # Add explicit call to python executable if a Python script is passed as # first argument if not args: - print "Invalid arguments for salome_test_driver_gui.py. No command defined." + print("Invalid arguments for salome_test_driver_gui.py. No command defined.") - exit(1) + sys.exit(1) _, ext = os.path.splitext(args[0]) test_and_args = args @@@ -71,10 -71,12 +71,12 @@@ import traceback traceback.print_exc() pass - - salome_instance.stop() + try: + salome_instance.stop() + except: + pass if sys.platform == 'win32': timer.cancel() -# print "Exit test with status code:", res +# print("Exit test with status code:", res) - # exit(res) + # sys.exit(res) # diff --cc bin/salomeContext.py index e23aef7d6,2e63384f2..4f31c584f --- a/bin/salomeContext.py +++ b/bin/salomeContext.py @@@ -224,7 -222,7 +224,7 @@@ class SalomeContext 'car' : '_getCar', } - if not command in list(availableCommands.keys()): - if not command in availableCommands.keys(): ++ if command not in availableCommands: command = "start" options = args @@@ -263,18 -261,18 +263,18 @@@ try: res = getattr(self, command)(options) # run appropriate method return res or (None, None) - except SystemExit, returncode: + except SystemExit as returncode: if returncode != 0: - self.getLogger().error("SystemExit %s in method %s.", returncode, command) + self.getLogger().warning("SystemExit %s in method %s.", returncode, command) - sys.exit(returncode) + return returncode - except StandardError: ++ except SalomeContextException as e: ++ self.getLogger().error(e) ++ return 1 + except Exception: self.getLogger().error("Unexpected error:") import traceback traceback.print_exc() - sys.exit(1) - except SalomeContextException as e: - self.getLogger().error(e) - sys.exit(1) + return 1 - except SalomeContextException, e: - self.getLogger().error(e) - return 1 # def __setContextFromConfigFile(self, filename, reserved=None): @@@ -282,10 -280,10 +282,10 @@@ reserved = [] try: unsetVars, configVars, reservedDict = parseConfigFile(filename, reserved) - except SalomeContextException, e: + except SalomeContextException as e: msg = "%s"%e self.getLogger().error(msg) - sys.exit(1) + return 1 # unset variables for var in unsetVars: @@@ -473,9 -471,20 +473,20 @@@ Available options are if "-p" in args or "--ports" in args: import PortManager ports = PortManager.getBusyPorts() - print("SALOME instances are running on ports:", ports) - if ports: - print("Last started instance on port %s"%ports[-1]) + this_ports = ports['this'] + other_ports = ports['other'] + if this_ports or other_ports: - print "SALOME instances are running on the following ports:" ++ print("SALOME instances are running on the following ports:") + if this_ports: - print " This application:", this_ports ++ print(" This application:", this_ports) + else: - print " No SALOME instances of this application" ++ print(" No SALOME instances of this application") + if other_ports: - print " Other applications:", other_ports ++ print(" Other applications:", other_ports) + else: - print " No SALOME instances of other applications" ++ print(" No SALOME instances of other applications") + else: - print "No SALOME instances are running" ++ print("No SALOME instances are running") if "-s" in args or "--softwares" in args: if "-s" in args: @@@ -521,66 -530,64 +532,64 @@@ # def _makeCoffee(self, unused=None): - print " (" - print " ) (" - print " ___...(-------)-....___" - print " .-\"\" ) ( \"\"-." - print " .-\'``\'|-._ ) _.-|" - print " / .--.| `\"\"---...........---\"\"` |" - print " / / | |" - print " | | | |" - print " \\ \\ | |" - print " `\\ `\\ | |" - print " `\\ `| SALOME |" - print " _/ /\\ 4 EVER /" - print " (__/ \\ <3 /" - print " _..---\"\"` \\ /`\"\"---.._" - print " .-\' \\ / \'-." - print " : `-.__ __.-\' :" - print " : ) \"\"---...---\"\" ( :" - print " \'._ `\"--...___...--\"` _.\'" - print " \\\"\"--..__ __..--\"\"/" - print " \'._ \"\"\"----.....______.....----\"\"\" _.\'" - print " `\"\"--..,,_____ _____,,..--\"\"`" - print " `\"\"\"----\"\"\"`" - print "" - print " SALOME is working for you; what else?" - print "" + print(" (") + print(" ) (") + print(" ___...(-------)-....___") + print(" .-\"\" ) ( \"\"-.") + print(" .-\'``\'|-._ ) _.-|") + print(" / .--.| `\"\"---...........---\"\"` |") + print(" / / | |") + print(" | | | |") + print(" \\ \\ | |") + print(" `\\ `\\ | |") + print(" `\\ `| SALOME |") + print(" _/ /\\ 4 EVER /") + print(" (__/ \\ <3 /") + print(" _..---\"\"` \\ /`\"\"---.._") + print(" .-\' \\ / \'-.") + print(" : `-.__ __.-\' :") + print(" : ) \"\"---...---\"\" ( :") + print(" \'._ `\"--...___...--\"` _.\'") + print(" \\\"\"--..__ __..--\"\"/") + print(" \'._ \"\"\"----.....______.....----\"\"\" _.\'") + print(" `\"\"--..,,_____ _____,,..--\"\"`") + print(" `\"\"\"----\"\"\"`") + print("") + print(" SALOME is working for you; what else?") + print("") - sys.exit(0) # def _getCar(self, unused=None): - print " _____________" - print " ..---:::::::-----------. ::::;;." - print " .\'\"\"\"\"\"\" ;; \\ \":." - print " .\'\' ; \\ \"\\__." - print " .\' ;; ; \\\\\";" - print " .\' ; _____; \\\\/" - print " .\' :; ;\" \\ ___:\'." - print " .\'--........................... : = ____:\" \\ \\" - print " ..-\"\" \"\"\"\' o\"\"\" ; ; :" - print " .--\"\" .----- ..----... _.- --. ..-\" ; ; ; ;" - print " .\"\"_- \"--\"\"-----\'\"\" _-\" .-\"\" ; ; .-." - print " .\' .\' SALOME .\" .\" ; ; /. |" - print " /-./\' 4 EVER <3 .\" / _.. ; ; ;;;|" - print " : ;-.______ / _________==. /_ \\ ; ; ;;;;" - print " ; / | \"\"\"\"\"\"\"\"\"\"\".---.\"\"\"\"\"\"\" : /\" \". |; ; _; ;;;" - print " /\"-/ | / / / / ;|; ;-\" | ;\';" - print ":- : \"\"\"----______ / / ____. . .\"\'. ;; .-\"..T\" ." - print "\'. \" ___ \"\": \'\"\"\"\"\"\"\"\"\"\"\"\"\"\" . ; ; ;; ;.\" .\" \'--\"" - print " \", __ \"\"\" \"\"---... :- - - - - - - - - \' \' ; ; ; ;;\" .\"" - print " /. ; \"\"\"---___ ; ; ; ;|.\"\"" - print " : \": \"\"\"----. .-------. ; ; ; ;:" - print " \\ \'--__ \\ \\ \\ / | ; ;;" - print " \'-.. \"\"\"\"---___ : .______..\\ __/..-\"\"| ; ; ;" - print " \"\"--.. \"\"\"--\" m l s . \". . ;" - print " \"\"------... ..--\"\" \" :" - print " \"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\" \\ /" - print " \"------\"" - print "" - print " Drive your simulation properly with SALOME!" - print "" + print(" _____________") + print(" ..---:::::::-----------. ::::;;.") + print(" .\'\"\"\"\"\"\" ;; \\ \":.") + print(" .\'\' ; \\ \"\\__.") + print(" .\' ;; ; \\\\\";") + print(" .\' ; _____; \\\\/") + print(" .\' :; ;\" \\ ___:\'.") + print(" .\'--........................... : = ____:\" \\ \\") + print(" ..-\"\" \"\"\"\' o\"\"\" ; ; :") + print(" .--\"\" .----- ..----... _.- --. ..-\" ; ; ; ;") + print(" .\"\"_- \"--\"\"-----\'\"\" _-\" .-\"\" ; ; .-.") + print(" .\' .\' SALOME .\" .\" ; ; /. |") + print(" /-./\' 4 EVER <3 .\" / _.. ; ; ;;;|") + print(" : ;-.______ / _________==. /_ \\ ; ; ;;;;") + print(" ; / | \"\"\"\"\"\"\"\"\"\"\".---.\"\"\"\"\"\"\" : /\" \". |; ; _; ;;;") + print(" /\"-/ | / / / / ;|; ;-\" | ;\';") + print(":- : \"\"\"----______ / / ____. . .\"\'. ;; .-\"..T\" .") + print("\'. \" ___ \"\": \'\"\"\"\"\"\"\"\"\"\"\"\"\"\" . ; ; ;; ;.\" .\" \'--\"") + print(" \", __ \"\"\" \"\"---... :- - - - - - - - - \' \' ; ; ; ;;\" .\"") + print(" /. ; \"\"\"---___ ; ; ; ;|.\"\"") + print(" : \": \"\"\"----. .-------. ; ; ; ;:") + print(" \\ \'--__ \\ \\ \\ / | ; ;;") + print(" \'-.. \"\"\"\"---___ : .______..\\ __/..-\"\"| ; ; ;") + print(" \"\"--.. \"\"\"--\" m l s . \". . ;") + print(" \"\"------... ..--\"\" \" :") + print(" \"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\" \\ /") + print(" \"------\"") + print("") + print(" Drive your simulation properly with SALOME!") + print("") - sys.exit(0) # # Add the following two methods since logger is not pickable @@@ -606,17 -613,10 +615,10 @@@ if __name__ == "__main__": if len(sys.argv) == 3: - context = sys.argv[1] - args = sys.argv[2] - - context = pickle.loads(context.encode()) - args = pickle.loads(args.encode()) - context = pickle.loads(sys.argv[1]) - args = pickle.loads(sys.argv[2]) ++ context = pickle.loads(sys.argv[1].encode()) ++ args = pickle.loads(sys.argv[2].encode()) - (out, err) = context._startSalome(args) - if out: - sys.stdout.write(out) - if err: - sys.stderr.write(err) + context._startSalome(args) else: usage() #