Back to index

salome-kernel  6.5.0
omnipatch.py
Go to the documentation of this file.
00001 #  -*- coding: iso-8859-1 -*-
00002 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00003 #
00004 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00005 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00006 #
00007 # This library is free software; you can redistribute it and/or
00008 # modify it under the terms of the GNU Lesser General Public
00009 # License as published by the Free Software Foundation; either
00010 # version 2.1 of the License.
00011 #
00012 # This library is distributed in the hope that it will be useful,
00013 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 # Lesser General Public License for more details.
00016 #
00017 # You should have received a copy of the GNU Lesser General Public
00018 # License along with this library; if not, write to the Free Software
00019 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00020 #
00021 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00022 #
00023 
00024 """
00025   This patch of omniORB is made to make it work with multiple interpreters
00026   and to correct the problem of incomplete import of CORBA packages
00027   in some situations common in SALOME
00028 
00029   This patch add or modify functions in omniORB module.
00030 
00031   In multiple interpreters context, omniORB module is meant to be shared among
00032   all interpreters
00033 """
00034 import sys,string,imp
00035 import omniORB
00036 # Map of partially-opened modules
00037 _partialModules = {}
00038 # Map of modules to share
00039 shared_imported={}
00040 
00041 # Function to return a Python module for the required IDL module name
00042 def openModule(mname, fname=None):
00043     # Salome modification start
00044     # Be sure to use the right module dictionnary
00045     import sys
00046     # Salome modification end
00047 
00048     if mname == "CORBA":
00049         mod = sys.modules["omniORB.CORBA"]
00050         # Salome modification start
00051         shared_imported[mname]=mod
00052         # Salome modification end
00053 
00054     elif sys.modules.has_key(mname):
00055         mod = sys.modules[mname]
00056 
00057         if _partialModules.has_key(mname):
00058             pmod = _partialModules[mname]
00059             mod.__dict__.update(pmod.__dict__)
00060             del _partialModules[mname]
00061         # Salome modification start
00062         shared_imported[mname]=mod
00063         # Salome modification end
00064 
00065     elif _partialModules.has_key(mname):
00066         mod = _partialModules[mname]
00067 
00068     # Salome modification start
00069     elif shared_imported.get(mname) :
00070         mod = shared_imported[mname]
00071     # Salome modification end
00072 
00073     else:
00074         mod = newModule(mname)
00075 
00076 
00077     if not hasattr(mod, "__doc__") or mod.__doc__ is None:
00078         mod.__doc__ = "omniORB IDL module " + mname + "\n\n" + \
00079                       "Generated from:\n\n"
00080 
00081     if fname is not None:
00082         mod.__doc__ = mod.__doc__ + "  " + fname + "\n"
00083 
00084     return mod
00085 
00086 # Function to create a new module, and any parent modules which do not
00087 # already exist
00088 def newModule(mname):
00089     # Salome modification start
00090     # Be sure to use the right module dictionnary
00091     import sys
00092     # Salome modification end
00093 
00094     mlist   = string.split(mname, ".")
00095     current = ""
00096     mod     = None
00097 
00098     for name in mlist:
00099         current = current + name
00100 
00101         if sys.modules.has_key(current):
00102             mod = sys.modules[current]
00103 
00104         elif _partialModules.has_key(current):
00105             mod = _partialModules[current]
00106 
00107         else:
00108             newmod = imp.new_module(current)
00109             if mod: setattr(mod, name, newmod)
00110             _partialModules[current] = mod = newmod
00111 
00112         current = current + "."
00113 
00114     return mod
00115 
00116 # Function to update a module with the partial module store in the
00117 # partial module map
00118 def updateModule(mname):
00119     # Salome modification start
00120     # Be sure to use the right module dictionnary
00121     import sys
00122     # Salome modification end
00123     if _partialModules.has_key(mname):
00124         pmod = _partialModules[mname]
00125         mod  = sys.modules[mname]
00126         mod.__dict__.update(pmod.__dict__)
00127         del _partialModules[mname]
00128 
00129     # Salome modification start
00130     shared_imported[mname]=sys.modules[mname]
00131     # Salome modification end
00132 
00133 omniORB.updateModule=updateModule
00134 omniORB.newModule=newModule
00135 omniORB.openModule=openModule
00136