Salome HOME
This commit was generated by cvs2git to create tag 'V1_3_0'.
[modules/kernel.git] / src / SALOME_SWIG / kernel_shared_modules.py
1 """
2
3 """
4 import glob,os,sys
5
6 import import_hook
7 from import_hook import register_name
8 from import_hook import register_pattern
9
10 register_name("qt")
11 register_pattern(lambda(x):x.endswith("_idl"))
12
13 register_name("omniORB")
14 register_name("CosNaming")
15
16 register_name("Engines")
17 register_name("SALOME")
18 register_name("SALOMEDS")
19 register_name("SALOME_ModuleCatalog")
20
21 # BE CAREFUL
22 # Engines, SALOME, SALOMEDS must be imported in that order because :
23 # Engines imports SALOME_Component_idl
24 # SALOME imports SALOME_Session_idl and SALOME_Exception_idl which imports SALOME_Component_idl
25 # and SALOMEDS imports SALOMEDS_idl and SALOMEDS_Attributes_idl which imports SALOME_Exception_idl
26 # If SALOME is imported before Engines, that module would not be completely imported
27 import Engines
28 import SALOME
29 import SALOMEDS
30
31 import SALOME_ModuleCatalog
32 from SALOME_utilities import MESSAGE
33 #
34 # We search all Python CORBA (omniorb) modules.
35 # A Python CORBA module has 2 associated Python packages 
36 # These packages are named : <module_name> and <module_name>__POA
37 #
38 # Get the SALOMEPATH if set or else use KERNEL_ROOT_DIR that should be set.
39 salome_path=os.environ.get("SALOMEPATH",os.getenv("KERNEL_ROOT_DIR"))
40
41 # Register all CORBA modules in the path and python modules in shared_modules
42 path=salome_path.split(":")
43 #
44 for rep in path:
45    rep_salome=os.path.join(rep,"lib","python"+sys.version[:3],"site-packages","salome")
46    # Find all the *__POA packages in the path
47    for elem in glob.glob(os.path.join(rep_salome,"*__POA")):
48       if os.path.isdir(elem):
49          # Found a directory (Python package) named *__POA 
50          module__POA=os.path.basename(elem)
51          module=module__POA[:-5]
52          MESSAGE( "Register CORBA module: " + module + ". Directory: " + os.path.abspath(elem)[:-5] )
53          register_name(module)
54
55    # Now we import modules found in shared_modules directory
56    for elem in glob.glob(os.path.join(rep_salome,"shared_modules","*.py")):
57        module=os.path.basename(elem)[:-3]
58        MESSAGE( "Register Python module: " + module + ". Location: " + os.path.abspath(elem) )
59        register_name(module)
60
61 def init_shared_modules():
62    """
63       This function initializes shared modules that need to be
64    """
65    # EDF-CCAR:
66    # Problem with omniORB : omniORB creates a C Python module named  _omnipy
67    # this module has sub-modules : omni_func, ...
68    # _omnipy is quite a package but import with Python sub-interpreters does not seem to work
69    # To make it work we need to add those sub-modules in sys.modules
70    import sys
71    import _omnipy
72    sys.modules["_omnipy.omni_func"]=_omnipy.omni_func
73    sys.modules["_omnipy.poa_func"]=_omnipy.poa_func
74    sys.modules["_omnipy.poamanager_func"]=_omnipy.poamanager_func
75    sys.modules["_omnipy.orb_func"]=_omnipy.orb_func
76