Salome HOME
A patch from Paul RASCLE for: kernel documentation with doxygen, modification on...
[modules/kernel.git] / src / KERNEL_PY / omnipatch.py
1 # Copyright (C) 2005  OPEN CASCADE, CEA, EDF R&D, LEG
2 #           PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either 
6 # version 2.1 of the License.
7
8 # This library is distributed in the hope that it will be useful 
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
11 # Lesser General Public License for more details.
12
13 # You should have received a copy of the GNU Lesser General Public  
14 # License along with this library; if not, write to the Free Software 
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18
19 """
20   This patch of omniORB is made to make it work with multiple interpreters
21   and to correct the problem of incomplete import of CORBA packages
22   in some situations common in SALOME
23
24   This patch add or modify functions in omniORB module.
25
26   In multiple interpreters context, omniORB module is meant to be shared among
27   all interpreters
28 """
29 import sys,string,imp
30 import omniORB
31 # Map of partially-opened modules
32 _partialModules = {}
33 # Map of modules to share
34 shared_imported={}
35
36 # Function to return a Python module for the required IDL module name
37 def openModule(mname, fname=None):
38     # Salome modification start
39     # Be sure to use the right module dictionnary
40     import sys
41     # Salome modification end
42
43     if mname == "CORBA":
44         mod = sys.modules["omniORB.CORBA"]
45         # Salome modification start
46         shared_imported[mname]=mod
47         # Salome modification end
48
49     elif sys.modules.has_key(mname):
50         mod = sys.modules[mname]
51
52         if _partialModules.has_key(mname):
53             pmod = _partialModules[mname]
54             mod.__dict__.update(pmod.__dict__)
55             del _partialModules[mname]
56         # Salome modification start
57         shared_imported[mname]=mod
58         # Salome modification end
59
60     elif _partialModules.has_key(mname):
61         mod = _partialModules[mname]
62
63     # Salome modification start
64     elif shared_imported.get(mname) :
65         mod = shared_imported[mname]
66     # Salome modification end
67
68     else:
69         mod = newModule(mname)
70
71
72     if not hasattr(mod, "__doc__") or mod.__doc__ is None:
73         mod.__doc__ = "omniORB IDL module " + mname + "\n\n" + \
74                       "Generated from:\n\n"
75
76     if fname is not None:
77         mod.__doc__ = mod.__doc__ + "  " + fname + "\n"
78
79     return mod
80
81 # Function to create a new module, and any parent modules which do not
82 # already exist
83 def newModule(mname):
84     # Salome modification start
85     # Be sure to use the right module dictionnary
86     import sys
87     # Salome modification end
88
89     mlist   = string.split(mname, ".")
90     current = ""
91     mod     = None
92
93     for name in mlist:
94         current = current + name
95
96         if sys.modules.has_key(current):
97             mod = sys.modules[current]
98
99         elif _partialModules.has_key(current):
100             mod = _partialModules[current]
101
102         else:
103             newmod = imp.new_module(current)
104             if mod: setattr(mod, name, newmod)
105             _partialModules[current] = mod = newmod
106
107         current = current + "."
108
109     return mod
110
111 # Function to update a module with the partial module store in the
112 # partial module map
113 def updateModule(mname):
114     # Salome modification start
115     # Be sure to use the right module dictionnary
116     import sys
117     # Salome modification end
118     if _partialModules.has_key(mname):
119         pmod = _partialModules[mname]
120         mod  = sys.modules[mname]
121         mod.__dict__.update(pmod.__dict__)
122         del _partialModules[mname]
123
124     # Salome modification start
125     shared_imported[mname]=sys.modules[mname]
126     # Salome modification end
127
128 omniORB.updateModule=updateModule
129 omniORB.newModule=newModule
130 omniORB.openModule=openModule
131