From: Cédric Aguerre Date: Mon, 18 May 2015 16:33:26 +0000 (+0200) Subject: add SalomeInstance object X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9cc064b0dd03e9ca2fa8ebccb7733774c7df6015;p=modules%2Fkernel.git add SalomeInstance object add SalomeInstance object --- 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_instance.py b/bin/appliskel/salome_tester/salome_instance.py new file mode 100644 index 000000000..811333481 --- /dev/null +++ b/bin/appliskel/salome_tester/salome_instance.py @@ -0,0 +1,101 @@ +# Copyright (C) 2015 CEA/DEN, EDF R&D, OPEN CASCADE +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +import sys +import os + +# Example of args: +# args=["--gui", "--show-desktop=1", "--splash=0"] +# args=["--terminal","--modules=MED,PARAVIS,GUI"] +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: + # :WARNING: NOT TESTED YET + sys.argv += ["--gui"] + sys.argv += ["--show-desktop=1"] + sys.argv += ["--splash=0"] + #sys.argv += ["--standalone=study"] + #sys.argv += ["--embedded=SalomeAppEngine,cppContainer,registry,moduleCatalog"] + else: + sys.argv += ["--terminal"] + #sys.argv += ["--shutdown-servers=1"] + #sys.argv += ["--modules=MED,PARAVIS,GUI"] + pass + + import setenv + setenv.main(True) + import runSalome + runSalome.runSalome() + + 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 + # + + def stop(self): + import killSalomeWithPort + killSalomeWithPort.killMyPort(self.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/appliskel/salome_tester/salome_test_session.py b/bin/appliskel/salome_tester/salome_test_session.py deleted file mode 100644 index 8f193f572..000000000 --- a/bin/appliskel/salome_tester/salome_test_session.py +++ /dev/null @@ -1,76 +0,0 @@ -# Copyright (C) 2015 CEA/DEN, EDF R&D, OPEN CASCADE -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# - -import sys -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=[]): - sys.argv = ['runSalome'] + args - - if "INGUI" in args: - # :WARNING: NOT TESTED YET - sys.argv += ["--gui"] - sys.argv += ["--show-desktop=1"] - sys.argv += ["--splash=0"] - #sys.argv += ["--standalone=study"] - #sys.argv += ["--embedded=SalomeAppEngine,cppContainer,registry,moduleCatalog"] - else: - sys.argv += ["--terminal"] - 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: - session_server.emitMessage("connect_to_study") - session_server.emitMessage("activate_viewer/ParaView") - pass - - with open(log.name) as f: - port = int(f.readline()) - - os.remove(log.name) - return port -# - -# Terminate SALOME -def terminateSession(port): - import killSalomeWithPort - killSalomeWithPort.killMyPort(port) -# 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