Salome HOME
PR: merge from branch BR_UT_V310a2 tag BR_UT_V310a2_20051115
[modules/kernel.git] / src / KERNEL_PY / kernel_shared_modules.py
1 """
2
3 """
4 import import_hook
5
6 import glob,os,sys,string,imp
7
8 from import_hook import register_name
9 from import_hook import register_pattern
10
11 register_name("qt")
12 register_name("libSALOME_LifeCycleCORBA")
13 register_pattern(lambda(x):x.endswith("_idl"))
14 register_pattern(lambda(x):x.endswith("_Swig"))
15
16 register_name("CORBA")
17 import CORBA
18
19 register_name("omniORB")
20 import omniORB
21
22 register_name("CosNaming")
23 import CosNaming
24
25 # Modify omniORB to use right sys.modules dictionnary 
26 # with multi-interpreter feature
27 # openModule and newModule are functions of omniORB/__init__.py module
28 # modified to register modules to share
29 # Function to return a Python module for the required IDL module name
30 def openModule(mname, fname=None):
31     # Salome modification start
32     import sys
33     # Salome modification end
34
35     if mname == "CORBA":
36         mod = sys.modules["omniORB.CORBA"]
37     elif sys.modules.has_key(mname):
38         mod = sys.modules[mname]
39     else:
40         mod = newModule(mname)
41
42     # Salome modification start
43     import_hook.set_shared_imported(mname,mod)
44     # Salome modification end
45
46
47     if not hasattr(mod, "__doc__") or mod.__doc__ is None:
48         mod.__doc__ = "omniORB IDL module " + mname + "\n\n" + \
49                       "Generated from:\n\n"
50
51     if fname is not None:
52         mod.__doc__ = mod.__doc__ + "  " + fname + "\n"
53
54     return mod
55
56 # Function to create a new module, and any parent modules which do not
57 # already exist
58 def newModule(mname):
59     # Salome modification start
60     import sys
61     # Salome modification end
62
63     mlist   = string.split(mname, ".")
64     current = ""
65     mod     = None
66
67     for name in mlist:
68         current = current + name
69
70         if sys.modules.has_key(current):
71             mod = sys.modules[current]
72         else:
73             newmod = imp.new_module(current)
74             if mod: setattr(mod, name, newmod)
75             sys.modules[current] = mod = newmod
76
77         current = current + "."
78
79     return mod
80 # Replace openModule and newModule by modified ones
81 # to take into account the sys.modules that matches
82 # the right one (multi-interpreter feature)
83 omniORB.openModule=openModule
84 omniORB.newModule=newModule
85
86 # BE CAREFUL
87 # Engines, SALOME, SALOMEDS must be imported in that order because :
88 # Engines imports SALOME_Component_idl
89 # SALOME imports SALOME_Session_idl and SALOME_Exception_idl which imports SALOME_Component_idl
90 # and SALOMEDS imports SALOMEDS_idl and SALOMEDS_Attributes_idl which imports SALOME_Exception_idl
91 # If SALOME is imported before Engines, that module would not be completely imported
92 import Engines
93 import SALOME
94 import SALOMEDS
95 import SALOME_ModuleCatalog
96
97 def init_shared_modules():
98    """
99       This function initializes shared modules that need to be
100    """
101    # EDF-CCAR:
102    # Problem with omniORB : omniORB creates a C Python module named  _omnipy
103    # this module has sub-modules : omni_func, ...
104    # _omnipy is quite a package but import with Python sub-interpreters does not seem to work
105    # To make it work we need to add those sub-modules in sys.modules
106    import sys
107    import _omnipy
108    sys.modules["_omnipy.omni_func"]=_omnipy.omni_func
109    sys.modules["_omnipy.poa_func"]=_omnipy.poa_func
110    sys.modules["_omnipy.poamanager_func"]=_omnipy.poamanager_func
111    sys.modules["_omnipy.orb_func"]=_omnipy.orb_func
112