Salome HOME
CCAR (EDF-RD):
[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 # That module is normally installed in shared_modules
39 # So we should find CORBA shared modules in ..
40 repertoire=os.path.join(os.path.dirname(__file__),'..')
41 path=[repertoire,]
42 #
43 for rep in path:
44    # Add rep directory in the Python path to be able to import modules 
45    listdir=glob.glob(os.path.join(rep,"*__POA"))
46    for elem in listdir:
47       if os.path.isdir(elem):
48          # Found a directory (Python package) named *__POA 
49          module__POA=os.path.basename(elem)
50          module=module__POA[:-5]
51          MESSAGE( "Import CORBA module: " + module + ".\n Directory: " + os.path.abspath(elem)[:-5] )
52          register_name(module)
53
54    # Now we import modules found in shared_modules directory
55    r=os.path.join(rep,"shared_modules")
56    if os.path.isdir(r):
57       listfich=glob.glob(os.path.join(r,"*.py"))
58       MESSAGE( str(listfich) )
59       for m in listfich:
60          module=os.path.basename(m)[:-3]
61          MESSAGE( "Import module: " + module + ".\n Location: " + os.path.abspath(m) )
62          register_name(module)
63
64
65 def init_shared_modules():
66    """
67       This function initializes shared modules that need to be
68    """
69    # EDF-CCAR:
70    # Problem with omniORB : omniORB creates a C Python module named  _omnipy
71    # this module has sub-modules : omni_func, ...
72    # _omnipy is quite a package but import with Python sub-interpreters does not seem to work
73    # To make it work we need to add those sub-modules in sys.modules
74    import sys
75    import _omnipy
76    sys.modules["_omnipy.omni_func"]=_omnipy.omni_func
77    sys.modules["_omnipy.poa_func"]=_omnipy.poa_func
78    sys.modules["_omnipy.poamanager_func"]=_omnipy.poamanager_func
79    sys.modules["_omnipy.orb_func"]=_omnipy.orb_func
80