From 311fde0cfaf288c7c3b317ed918c6c25b13e83f6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=A9dric=20Aguerre?= Date: Mon, 18 May 2015 18:33:26 +0200 Subject: [PATCH] add SalomeInstance object add SalomeInstance object --- bin/appliskel/salome_tester/CMakeLists.txt | 2 +- ...ome_test_session.py => salome_instance.py} | 73 +++++++++++++------ .../salome_tester/salome_test_driver.py | 9 ++- bin/salomeContext.py | 11 ++- 4 files changed, 62 insertions(+), 33 deletions(-) rename bin/appliskel/salome_tester/{salome_test_session.py => salome_instance.py} (58%) diff --git a/bin/appliskel/salome_tester/CMakeLists.txt b/bin/appliskel/salome_tester/CMakeLists.txt index 18ed43fe8..6a1688a0e 100644 --- a/bin/appliskel/salome_tester/CMakeLists.txt +++ b/bin/appliskel/salome_tester/CMakeLists.txt @@ -19,7 +19,7 @@ SET(SCRIPTS salome_test_driver.py - salome_test_session.py + salome_instance.py ) SALOME_INSTALL_SCRIPTS("${SCRIPTS}" ${SALOME_INSTALL_SCRIPT_SCRIPTS}/appliskel) diff --git a/bin/appliskel/salome_tester/salome_test_session.py b/bin/appliskel/salome_tester/salome_instance.py similarity index 58% rename from bin/appliskel/salome_tester/salome_test_session.py rename to bin/appliskel/salome_tester/salome_instance.py index 8f193f572..811333481 100644 --- a/bin/appliskel/salome_tester/salome_test_session.py +++ b/bin/appliskel/salome_tester/salome_instance.py @@ -23,8 +23,37 @@ import os # Example of args: # args=["--gui", "--show-desktop=1", "--splash=0"] # args=["--terminal","--modules=MED,PARAVIS,GUI"] -class SalomeSession(object): - def __init__(self, args=[]): +class SalomeInstance(object): + + def __init__(self): + self.port = None + # + + def get_port(self): + return self.port + # + + @staticmethod + def start(shutdown_servers=False): + import tempfile + log = tempfile.NamedTemporaryFile(suffix='_nsport.log', delete=False) + log.close() + + instance_args = [ + "--ns-port-log=%s"%log.name, + "--shutdown-servers=%d"%shutdown_servers + ] + salome_instance = SalomeInstance() + salome_instance.__run(args=instance_args) + + with open(log.name) as f: + salome_instance.port = int(f.readline()) + + os.remove(log.name) + return salome_instance + # + + def __run(self, args=[]): sys.argv = ['runSalome'] + args if "INGUI" in args: @@ -36,41 +65,37 @@ class SalomeSession(object): #sys.argv += ["--embedded=SalomeAppEngine,cppContainer,registry,moduleCatalog"] else: sys.argv += ["--terminal"] - sys.argv += ["--shutdown-servers=1"] + #sys.argv += ["--shutdown-servers=1"] #sys.argv += ["--modules=MED,PARAVIS,GUI"] pass import setenv setenv.main(True) - import runSalome runSalome.runSalome() - # -# -# Run SALOME -def startSession(): - import tempfile - log = tempfile.NamedTemporaryFile(suffix='_nsport.log', delete=False) - log.close() - import salome - salome_session = SalomeSession(args=["--ns-port-log=%s"%log.name]) - salome.salome_init() - session_server = salome.naming_service.Resolve('/Kernel/Session') - if session_server: + import salome + salome.salome_init() + session_server = salome.naming_service.Resolve('/Kernel/Session') + if session_server: session_server.emitMessage("connect_to_study") session_server.emitMessage("activate_viewer/ParaView") pass + # - with open(log.name) as f: - port = int(f.readline()) + def stop(self): + import killSalomeWithPort + killSalomeWithPort.killMyPort(self.port) + # - os.remove(log.name) - return port # -# Terminate SALOME -def terminateSession(port): - import killSalomeWithPort - killSalomeWithPort.killMyPort(port) +if __name__ == "__main__": + print "##### Start instance..." + salome_instance = SalomeInstance.start() + port = salome_instance.get_port() + print "##### ...instance started on port %s"%port + + print "##### Terminate instance running on port %s"%port + salome_instance.stop() # diff --git a/bin/appliskel/salome_tester/salome_test_driver.py b/bin/appliskel/salome_tester/salome_test_driver.py index ee468557b..4db007c77 100644 --- a/bin/appliskel/salome_tester/salome_test_driver.py +++ b/bin/appliskel/salome_tester/salome_test_driver.py @@ -110,11 +110,12 @@ if __name__ == "__main__": signal.alarm(abs(int(timeout_delay)-10)) signal.signal(signal.SIGALRM, timeoutHandler) - # Run test in a new SALOME session - from salome_test_session import startSession, terminateSession + # Run test in a new SALOME instance + from salome_instance import SalomeInstance res = 1 try: - port = startSession() + salome_instance = SalomeInstance.start(shutdown_servers=True) + port = salome_instance.get_port() res, out, err = runTest(test_and_args) #res = processResult(res, out, err) res = processResultSpecialParavis(res, out, err) @@ -125,7 +126,7 @@ if __name__ == "__main__": traceback.print_exc() pass - terminateSession(port) + salome_instance.stop() print "Exit test with status code:", res exit(res) # diff --git a/bin/salomeContext.py b/bin/salomeContext.py index 384db9bf5..4c7a45024 100644 --- a/bin/salomeContext.py +++ b/bin/salomeContext.py @@ -239,13 +239,16 @@ class SalomeContext: See usage for details on commands. """ def _startSalome(self, args): + import os + import sys try: - import os + from setenv import add_path absoluteAppliPath = os.getenv('ABSOLUTE_APPLI_PATH') - import sys path = os.path.realpath(os.path.join(absoluteAppliPath, "bin", "salome")) - if not path in sys.path: - sys.path[:0] = [path] + add_path(path, "PYTHONPATH") + path = os.path.realpath(os.path.join(absoluteAppliPath, "bin", "salome", "appliskel")) + add_path(path, "PYTHONPATH") + except: pass -- 2.39.2