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