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