+ Initialize SALOME client process (that can also be server).
+ 3 modes of initialization exists:
+ - SSL mode (see salome_init_without_session)
+ - SSL mode attached in the context of python execution inside SALOME_Container_No_NS_Serv server (typically YACS)
+ - Classical mode (see salome_init_with_session)
+ :param iorfakensfile: filename inside which IOR of fake NS will be written
+ :param forced: tell if the multi-initialization protection mecanism of salome_init must be skiped of not
+ (typically in the context where a path to a study is given whereas a previous initialisation without it was done)
+ """
+ if not forced:
+ if lcc is not None:# multi-initialization protection mecanism is based on lcc global var
+ return
+ PATH_TO_STUDY_FILE_TO_INITIATE = "PATH_TO_STUDY_FILE_TO_INITIATE"
+ import KernelBasis
+ if KernelBasis.getSSLMode():
+ if KernelBasis.getIOROfEmbeddedNS() == "":
+ import os
+ # make runSalome.py -t study.hdf toto.py
+ if path is None and PATH_TO_STUDY_FILE_TO_INITIATE in os.environ:
+ path = os.environ[PATH_TO_STUDY_FILE_TO_INITIATE]
+ salome_init_without_session(path, embedded, iorfakensfile)
+ else:
+ salome_init_without_session_attached(path, embedded)
+ else:
+ salome_init_with_session(path, embedded)
+
+def salome_init_without_session_common(path=None, embedded=False):
+ from ORBConfigFile import writeORBConfigFileSSL
+ OMNIORB_USER_PATH = "OMNIORB_USER_PATH"
+ def RemoveOmniorbConfigFile():
+ import os
+ if "OMNIORB_CONFIG" in os.environ:
+ fileToRemove = os.environ["OMNIORB_CONFIG"]
+ if os.path.exists(fileToRemove):
+ os.unlink(fileToRemove)
+
+ if OMNIORB_USER_PATH in os.environ:
+ import atexit
+ writeORBConfigFileSSL(os.environ[OMNIORB_USER_PATH],kwargs={"with_pid":True})
+ atexit.register(RemoveOmniorbConfigFile)
+
+ global lcc,naming_service,myStudy,myStudyName,orb,modulcat,sg
+ import KernelBasis
+ KernelBasis.setSSLMode(True)
+ import KernelDS
+ myStudy = KernelDS.myStudy()
+ import CORBA
+ orb=CORBA.ORB_init([''])
+ import KernelModuleCatalog
+ import SALOME_ModuleCatalog
+ from salome_kernel import list_of_catalogs_regarding_environement
+ modulcat = KernelModuleCatalog.myModuleCatalog( list_of_catalogs_regarding_environement() )
+ #
+ poa = orb.resolve_initial_references("RootPOA")
+ poaManager = poa._get_the_POAManager()
+ poaManager.activate()
+ #
+ sg = salome_iapp_init(embedded)
+ salome_study_init_without_session(path)
+ #
+ from NamingService import NamingService
+ naming_service = NamingService()
+ myStudyName = myStudy.Name
+
+def salome_init_without_session(path=None, embedded=False, iorfakensfile=None):
+ """
+ Force creation of all servants needed by SALOME session in the current process.
+ A Fake NamingService is created storing reference of all servants in the current process.
+ """
+ salome_init_without_session_common(path,embedded)
+ global lcc,cm,dsm,esm,rm,logm
+ import KernelLauncher
+ cm = KernelLauncher.myContainerManager()
+ type(cm).SetOverrideEnvForContainersSimple = ContainerManagerSetOverrideEnvForContainersSimple
+ rm = KernelLauncher.myResourcesManager()
+ from LifeCycleCORBA import LifeCycleCORBASSL
+ lcc = LifeCycleCORBASSL()
+ # create a FactoryServer Container servant
+ import KernelContainer
+ KernelContainer.myContainer()
+ # activate poaManager to accept co-localized CORBA calls.
+ from KernelSDS import GetDSMInstance
+ import sys
+ if hasattr(sys, 'argv'):
+ argv = sys.argv
+ else:
+ argv = ['']
+ dsm = GetDSMInstance(argv)
+ # esm inherits from SALOME_CPythonHelper singleton already initialized by GetDSMInstance
+ # esm inherits also from SALOME_ResourcesManager creation/initialization (concerning SingleThreadPOA POA) when KernelLauncher.GetContainerManager() has been called
+ esm = KernelLauncher.GetExternalServer()
+ # idem for logm
+ logm = KernelLauncher.myLogManager()
+ type(logm).NaiveFetch = LogManagerNaiveFetch
+ type(logm).Fetch = LogManagerFetch
+ type(logm).DumpInFile = LogManagerDumpInFile
+ type(logm).LaunchMonitoringDumpFile = LogManagerLaunchMonitoringDumpFile
+ type(logm).FinalFetchBeforeDying = LogManagerFinalFetchBeforeDying
+ type(logm).GetLatestMonitoringDumpFile = LogManagerGetLatestMonitoringDumpFile
+ type(logm).DumpIORInFile = LogManagerDumpIORInFile
+ #
+ import KernelLogger
+ naming_service.Register(KernelLogger.myLogger(),"/Logger")
+ #
+ from NamingService import NamingService
+ if iorfakensfile is not None:
+ with open(iorfakensfile,"w") as iorfakensf:
+ iorfakensf.write(NamingService.IOROfNS())
+
+CM_NAME_IN_NS = "/ContainerManager"
+RM_NAME_IN_NS = "/ResourcesManager"
+DSM_NAME_IN_NS = "/DataServerManager"
+ESM_NAME_IN_NS = "/ExternalServers"
+LOGM_NAME_IN_NS = "/LogManager"
+
+def salome_init_without_session_attached(path=None, embedded=False):
+ """
+ Configuration SSL inside a python interpretor launched in the SALOME_Container_No_NS_Serv.
+ In this configuration, a local FakeNamingService is created and remote objects are stored in it.
+ lcc is pointing to the FakeNamingService above.
+ """
+ salome_init_without_session_common(path,embedded)
+ global lcc,cm,dsm,esm,rm,logm
+ import CORBA
+ orb=CORBA.ORB_init([''])
+ import Engines
+ import KernelBasis
+ nsAbroad = orb.string_to_object( KernelBasis.getIOROfEmbeddedNS() )
+ import SALOME
+ cm = orb.string_to_object( nsAbroad.Resolve(CM_NAME_IN_NS).decode() )
+ type(cm).SetOverrideEnvForContainersSimple = ContainerManagerSetOverrideEnvForContainersSimple
+ naming_service.Register(cm,CM_NAME_IN_NS)
+ rm = orb.string_to_object( nsAbroad.Resolve(RM_NAME_IN_NS).decode() )
+ naming_service.Register(rm,RM_NAME_IN_NS)
+ #
+ from LifeCycleCORBA import LifeCycleCORBASSL
+ lcc = LifeCycleCORBASSL()
+ dsm = orb.string_to_object( nsAbroad.Resolve(DSM_NAME_IN_NS).decode() )
+ naming_service.Register(dsm,DSM_NAME_IN_NS)
+ #
+ esm = orb.string_to_object( nsAbroad.Resolve(ESM_NAME_IN_NS).decode() )
+ naming_service.Register(esm,ESM_NAME_IN_NS)
+ #
+ logm = orb.string_to_object( nsAbroad.Resolve(LOGM_NAME_IN_NS).decode() )
+ naming_service.Register(logm,LOGM_NAME_IN_NS)
+
+def salome_init_with_session(path=None, embedded=False):
+ """
+ Performs only once SALOME general purpose initialisation for scripts.