]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
add SalomeInstance object
authorCédric Aguerre <cedric.aguerre@edf.fr>
Mon, 18 May 2015 16:33:26 +0000 (18:33 +0200)
committerCédric Aguerre <cedric.aguerre@edf.fr>
Mon, 18 May 2015 16:34:48 +0000 (18:34 +0200)
add SalomeInstance object

bin/appliskel/salome_tester/CMakeLists.txt
bin/appliskel/salome_tester/salome_instance.py [new file with mode: 0644]
bin/appliskel/salome_tester/salome_test_driver.py
bin/appliskel/salome_tester/salome_test_session.py [deleted file]
bin/salomeContext.py

index 18ed43fe865ff3250359cac8db74753ab157f29c..6a1688a0eada9d89a7f5b2d8a6639d037b4ea3d7 100644 (file)
@@ -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 (file)
index 0000000..8113334
--- /dev/null
@@ -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()
+#
index ee468557b3643d9167c4e2ddf273841c7248a087..4db007c77409c930e808f675a6de1c0d9a59bc42 100644 (file)
@@ -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 (file)
index 8f193f5..0000000
+++ /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)
-#
index 384db9bf558e2db9f42d2ea796bf35e08cf80709..4c7a45024aa1eccb5be214f28afb9ec48f8f6c80 100644 (file)
@@ -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