Salome HOME
Updated copyright comment
[modules/gui.git] / src / PVServerService / ENGINE / PVSERVER_impl.py
index cdec0ee069945922c8d0bf5eb97853abc8a0ca9c..c7b6a6c70d5dc1e17227563ff943c6b9307bf8b0 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2007-2015  CEA/DEN, EDF R&D
+# Copyright (C) 2015-2024  CEA, EDF, OPEN CASCADE
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -23,7 +23,8 @@ import subprocess as subp
 import socket
 from time import sleep
 import os
-from SALOME import SALOME_Exception
+import sys
+from SALOME import SALOME_Exception, ExceptionStruct, INTERNAL_ERROR
 #from SALOME_utilities import MESSAGE
 
 def MESSAGE(m):
@@ -49,14 +50,22 @@ class PVSERVER_impl(object):
             raise Exception("PVSERVER_Impl.__init__ : \"import paraview\" failed !")
         # deduce dynamically PARAVIEW_ROOT_DIR from the paraview module location
         self.PARAVIEW_ROOT_DIR = None
-        ZE_KEY_TO_FIND_PV_ROOT_DIR="lib"
+        if sys.platform == "win32":
+          ZE_KEY_TO_FIND_PV_ROOT_DIR=["Lib"]
+          upCount =2
+        else:
+          ZE_KEY_TO_FIND_PV_ROOT_DIR=["lib", "lib64"]
+          upCount =1
+        tmp = os.path.sep.join(tmp.split('/'))
         li=tmp.split(os.path.sep) ; li.reverse()
-        if ZE_KEY_TO_FIND_PV_ROOT_DIR not in li:
-            raise SALOME_Exception(SALOME.ExceptionStruct(SALOME.INTERNAL_ERROR,
-                      "PVSERVER_Impl.__init__ : error during dynamic deduction of PARAVIEW_ROOT_DIR : Loc of paraview module is \"%s\" ! \"%s\" is supposed to be the key to deduce it !"%(tmp,ZE_KEY_TO_FIND_PV_ROOT_DIR),
-                      "PVSERVER.py", 0))
-        li=li[li.index("lib")+1:] ; li.reverse()
-        self.PARAVIEW_ROOT_DIR = os.path.sep.join(li)
+        for key_to_find in ZE_KEY_TO_FIND_PV_ROOT_DIR:
+            if key_to_find in li:
+                li=li[li.index(key_to_find)+upCount:] ; li.reverse()
+                self.PARAVIEW_ROOT_DIR = os.path.sep.join(li)
+                return                
+        raise SALOME_Exception(ExceptionStruct(INTERNAL_ERROR,
+                                               "PVSERVER_Impl.__init__ : error during dynamic deduction of PARAVIEW_ROOT_DIR : Loc of paraview module is \"%s\" ! \"%s\" is supposed to be the key to deduce it !"%(tmp," or ".join(ZE_KEY_TO_FIND_PV_ROOT_DIR)),
+                                               "PVSERVER.py", 0))
 
     """
     Private. Identify a free port to launch the PVServer. 
@@ -77,7 +86,7 @@ class PVSERVER_impl(object):
                 cnt += 1
                 currPort += 1
                 pass
-        raise SALOME_Exception(SALOME.ExceptionStruct(SALOME.INTERNAL_ERROR,
+        raise SALOME_Exception(ExceptionStruct(INTERNAL_ERROR,
                             "[PVSERVER] maximum number of tries to retrieve a free port for the PVServer",
                             "PVSERVER.py", 0))
                                            
@@ -101,7 +110,7 @@ class PVSERVER_impl(object):
         opt = []
         if port <= 0:
             port = self.__getFreePort(self.PVSERVER_DEFAULT_PORT)
-        self.pvserverPop = subp.Popen([pvServerPath, "--multi-clients", "--server-port=%d" % port, "--use-offscreen-rendering"])
+        self.pvserverPop = subp.Popen([pvServerPath, "--multi-clients", "--server-port=%d" % port, "--force-offscreen-rendering"])
         sleep(3)  # Give some time to the server to start up to avoid 
                   # ugly messages on the client side saying that it cannot connect
         # Is PID still alive? If yes, consider that the launch was successful
@@ -111,7 +120,7 @@ class PVSERVER_impl(object):
             self.pvserverPort = port
             MESSAGE("[PVSERVER] pvserver successfully launched on port %d" % port)
         else:
-            raise SALOME_Exception(SALOME.ExceptionStruct(SALOME.INTERNAL_ERROR,
+            raise SALOME_Exception(ExceptionStruct(INTERNAL_ERROR,
                             "[PVSERVER] Unable to start PVServer on port %d!" % port,
                             "PVSERVER.py", 0))
         return "cs://%s:%d" % (host, self.pvserverPort)
@@ -135,4 +144,3 @@ class PVSERVER_impl(object):
         return self.isGUIConnected
 
 
-      
\ No newline at end of file