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