Salome HOME
Python container is obsolete
[modules/kernel.git] / bin / runSalome.py
index acb9c981f4f89a3d45727e952c4485a6e5af1507..62252e6e2c8671ded5e51b14ffcc1e76f5f9c883 100755 (executable)
@@ -32,9 +32,7 @@ import setenv
 from launchConfigureParser import verbose
 from server import process_id, Server
 import json
-from salomeLauncherUtils import formatScriptsAndArgs
 import subprocess
-import PortManager
 
 # -----------------------------------------------------------------------------
 
@@ -66,7 +64,7 @@ def givenPortKill(port):
     try:
         killMyPort(my_port)
     except:
-        print "problem in LocalPortKill(), killMyPort("<<port<<")"
+        print "problem in LocalPortKill(), killMyPort(%s)"%port
         pass
     pass
 
@@ -141,7 +139,28 @@ 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):
@@ -263,6 +282,9 @@ 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'])
@@ -496,6 +518,12 @@ def startSalome(args, modules_list, modules_root_dir):
       myServer=NotifyServer(args,modules_root_dir)
       myServer.run()
 
+    # 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
+        os.environ["PYTHONPATH"] = "/tmp/SimanSalome/" + args['siman_study'] + "/" + \
+                                   args['siman_scenario'] + "/" + args['siman_user'] + os.pathsep + os.environ["PYTHONPATH"];
+
     # Launch  Session Server (to show splash ASAP)
     #
 
@@ -586,11 +614,6 @@ def startSalome(args, modules_list, modules_root_dir):
         else:
           clt.waitNSPID("/Containers/" + theComputer + "/FactoryServer",myServer.PID)
 
-    #
-    # Launch local Python Container (FactoryServerPy),
-    # and wait until it is registered in naming service
-    #
-
     if 'pyContainer' in args['standalone']:
         raise Exception('Python containers no longer supported')
 
@@ -649,6 +672,27 @@ 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
 
 # -----------------------------------------------------------------------------
@@ -729,10 +773,12 @@ def useSalome(args, modules_list, modules_root_dir):
                 if not args['gui'] or not args['session_gui']:
                     toimport = args['pyscript']
 
+        from salomeLauncherUtils import formatScriptsAndArgs
         command = formatScriptsAndArgs(toimport)
         if command:
             proc = subprocess.Popen(command, shell=True)
-            proc.wait()
+            res = proc.wait()
+            if res: sys.exit(1) # if there's an error when executing script, we should explicitly exit
 
     return clt
 
@@ -770,7 +816,6 @@ def no_main():
     args, modules_list, modules_root_dir = pickle.load(fenv)
     fenv.close()
     kill_salome(args)
-    PortManager.start_server(nbSimultaneous=25, timeout=10)
     from searchFreePort import searchFreePort
     searchFreePort(args, 0)
     clt = useSalome(args, modules_list, modules_root_dir)
@@ -781,16 +826,13 @@ def no_main():
 def main():
     """Salome launch as a main application"""
 
-    ### TEMP >>> ###
-    if not os.getenv("OMNIORB_USER_PATH"):
-        homePath = os.path.realpath(os.path.expanduser('~'))
-        #defaultOmniorbUserPath = os.path.join(homePath, ".salomeConfig/USERS")
-        defaultOmniorbUserPath = homePath
-        if os.getenv("APPLI"):
-            defaultOmniorbUserPath = os.path.join(homePath, os.getenv("APPLI"), "USERS")
-        os.environ["OMNIORB_USER_PATH"] = defaultOmniorbUserPath
-        pass
-    ### <<< TEMP ###
+    # define folder to store omniorb config (initially in virtual application folder)
+    try:
+        from salomeLauncherUtils import setOmniOrbUserPath
+        setOmniOrbUserPath()
+    except Exception, e:
+        print e
+        sys.exit(1)
 
     from salome_utils import getHostName
     print "runSalome running on %s" % getHostName()
@@ -806,7 +848,6 @@ def main():
         test = False
         pass
     if test:
-        PortManager.start_server(nbSimultaneous=25, timeout=10)
         from searchFreePort import searchFreePort
         searchFreePort(args, save_config, args.get('useport'))
         pass