Salome HOME
Windows compatibility.
[modules/yacs.git] / bin / runSalome.py
index 6439d4e5486cc1d3bf5154ee1e8588aca63e6813..e6e79763937eb85ad290b51fa9c2ff262ba0d379 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 #  -*- coding: iso-8859-1 -*-
-# Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
+# Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 #
 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -41,7 +41,7 @@ from killSalome import killAllPorts
 
 def killLocalPort():
     """
-    kill servers from a previous SALOME exection, if needed,
+    kill servers from a previous SALOME execution, if needed,
     on the CORBA port given in args of runSalome
     """
 
@@ -56,7 +56,7 @@ def killLocalPort():
 
 def givenPortKill(port):
     """
-    kill servers from a previous SALOME exection, if needed,
+    kill servers from a previous SALOME execution, if needed,
     on the same CORBA port
     """
 
@@ -89,21 +89,21 @@ def kill_salome(args):
 class InterpServer(Server):
     def __init__(self,args):
         self.args=args
-        if sys.platform != "win32":
-          env_ld_library_path=['env', 'LD_LIBRARY_PATH=' + os.getenv("LD_LIBRARY_PATH")]
-          self.CMD=['xterm', '-e']+ env_ld_library_path + ['python']
-        else:
+        if sys.platform == "win32":
           self.CMD=['cmd', '/c', 'start cmd.exe', '/K', 'python']
+        elif sys.platform == "darwin":
+          env_ld_library_path=['env', 'DYLD_LIBRARY_PATH=' + os.getenv("LD_LIBRARY_PATH")]
+          self.CMD=['xterm', '-e'] + env_ld_library_path + ['python']
+        else:
+          env_ld_library_path=['env', 'LD_LIBRARY_PATH=' + os.getenv("LD_LIBRARY_PATH")]
+          self.CMD=['xterm', '-e'] + env_ld_library_path + ['python']
 
     def run(self):
         global process_id
         command = self.CMD
         print "INTERPSERVER::command = ", command
-        if sys.platform == "win32":
-          import win32pm
-          pid = win32pm.spawnpid( string.join(command, " "),'-nc' )
-        else:
-          pid = os.spawnvp(os.P_NOWAIT, command[0], command)
+        import subprocess
+        pid = subprocess.Popen(command).pid
         process_id[pid]=self.CMD
         self.PID = pid
 
@@ -140,29 +140,6 @@ def get_cata_path(list_modules,modules_root_dir):
 
     return cata_path
 
-_siman_name = None
-def simanStudyName(args):
-    global _siman_name
-    if _siman_name is None:
-        # siman session paramenters and checkout processing
-        _siman_name = ""
-        if 'siman' in args:
-            siman_data = []
-            for param in [ 'study', 'scenario', 'user']:
-                siman_param = "siman_%s"%param
-                if siman_param in args:
-                    siman_data.append(args[siman_param])
-                else:
-                    print "SIMAN %s must be defined using parameter --siman-%s=XXX" % (siman_param, siman_param)
-                    pass
-                pass
-            if len(siman_data) == 3:
-                _siman_name = "_".join(siman_data)
-                pass
-            pass
-        pass
-    return _siman_name
-
 class CatalogServer(Server):
     def __init__(self,args):
         self.args=args
@@ -212,10 +189,18 @@ class RegistryServer(Server):
 # ---
 
 class ContainerCPPServer(Server):
-    def __init__(self,args):
+    def __init__(self,args,with_gui=False):
         self.args=args
         self.initArgs()
         self.CMD=['SALOME_Container','FactoryServer']
+        if not with_gui and self.args["valgrind_session"]:
+            l = ["valgrind"]
+            val = os.getenv("VALGRIND_OPTIONS")
+            if val:
+                l += val.split()
+                pass
+            self.CMD = l + self.CMD
+            pass
 
 # ---
 
@@ -281,9 +266,6 @@ class SessionServer(Server):
                 if self.args['study_hdf'] is not None:
                     self.SCMD2+=['--study-hdf=%s'%self.args['study_hdf']]
                     pass
-                if simanStudyName(self.args):
-                    self.SCMD2+=['--siman-study=%s'%simanStudyName(self.args)]
-                    pass
                 pass
                 if self.args.has_key('pyscript') and len(self.args['pyscript']) > 0:
                     msg = json.dumps(self.args['pyscript'], cls=ScriptAndArgsObjectEncoder)
@@ -309,6 +291,8 @@ class SessionServer(Server):
             list_modules.reverse()
             self.SCMD2+=['--modules (%s)' % ":".join(list_modules)]
             pass
+        if self.args.has_key('language'):
+            self.SCMD2+=['--language=%s' % self.args['language']]
         pass
 
     def setpath(self,modules_list,modules_root_dir):
@@ -484,14 +468,6 @@ def startSalome(args, modules_list, modules_root_dir):
         myServer.run()
         clt.waitLogger("Logger")
 
-    # set siman python path before the session server launching to import scripts inside python console
-    if simanStudyName(args):
-        # MPV: use os.environ here because session server is launched in separated process and sys.path is missed in this case
-        from salome_utils import getTmpDir
-        ppath = os.path.join(getTmpDir, "SimanSalome", args['siman_study'],
-                             args['siman_scenario'], args['siman_user'])
-        os.environ["PYTHONPATH"] = ppath + os.pathsep + os.environ["PYTHONPATH"]
-
     # Launch  Session Server (to show splash ASAP)
     #
 
@@ -575,7 +551,7 @@ def startSalome(args, modules_list, modules_root_dir):
     #
 
     if ('cppContainer' in args['standalone']) | (args["gui"] == 0) :
-        myServer=ContainerCPPServer(args)
+        myServer=ContainerCPPServer(args, with_gui=args["gui"]!=0)
         myServer.run()
         if sys.platform == "win32":
           clt.waitNS("/Containers/" + theComputer + "/FactoryServer")
@@ -611,7 +587,7 @@ def startSalome(args, modules_list, modules_root_dir):
     #    session.GetInterface()
 
     #
-    # additionnal external python interpreters
+    # additional external python interpreters
     #
     nbaddi=0
 
@@ -640,27 +616,6 @@ def startSalome(args, modules_list, modules_root_dir):
         except ImportError:
             pass
 
-    # siman session paramenters and checkout processing
-    if simanStudyName(args):
-        print '**********************************************'
-        print "Siman study name= '" + simanStudyName(args) + "'"
-        import SALOMEDS
-        obj = clt.Resolve('myStudyManager')
-        myStudyManager = obj._narrow(SALOMEDS.StudyManager)
-        aNewStudy = myStudyManager.NewStudy(simanStudyName(args))
-        aSimS = myStudyManager.GetSimanStudy()
-        aSimS._set_StudyId(args['siman_study'])
-        aSimS._set_ScenarioId(args['siman_scenario'])
-        aSimS._set_UserId(args['siman_user'])
-        aSimS.CheckOut(aNewStudy)
-        # if session server is enabled, activate the created study
-        if args["gui"]:
-            print "Activate the SIMAN study in the SALOME GUI"
-            obj = clt.Resolve('/Kernel/Session')
-            mySession = obj._narrow(SALOME.Session)
-            mySession.emitMessage("simanCheckoutDone " + simanStudyName(args))
-        print '**********************************************'
-
     return clt
 
 # -----------------------------------------------------------------------------
@@ -797,7 +752,7 @@ def no_main():
 
 # -----------------------------------------------------------------------------
 
-def main():
+def main(exeName=None):
     """Salome launch as a main application"""
 
     # define folder to store omniorb config (initially in virtual application folder)
@@ -809,7 +764,7 @@ def main():
         sys.exit(1)
 
     from salome_utils import getHostName
-    args, modules_list, modules_root_dir = setenv.get_config()
+    args, modules_list, modules_root_dir = setenv.get_config(exeName=exeName)
     print "runSalome running on %s" % getHostName()
 
     kill_salome(args)
@@ -901,7 +856,7 @@ def runSalome():
     test = args['gui'] and args['session_gui']
     test = test or args['wake_up_session']
     # --
-    # The next test covers the --pinter option or var PYTHONINSPECT setted
+    # The next test covers the --pinter option or if var PYTHONINSPECT is set
     # --
     test = test and not os.environ.get('PYTHONINSPECT')
     # --