From 40a955dae1a8ad1b4f28d355193dea2305e9cfd9 Mon Sep 17 00:00:00 2001 From: jfa Date: Tue, 15 Nov 2005 16:27:20 +0000 Subject: [PATCH] PAL10310: Probleme with incomplete import of python CORBA modules. Solution provided by Christian CAREMOLI --- src/SALOME_SWIG_WITHOUTIHM/Makefile.in | 2 +- .../kernel_shared_modules.py | 65 +------------ src/SALOME_SWIG_WITHOUTIHM/omnipatch.py | 97 +++++++++++++++++++ src/SALOME_SWIG_WITHOUTIHM/salome.py | 1 + .../salome_shared_modules.py | 3 +- 5 files changed, 103 insertions(+), 65 deletions(-) create mode 100644 src/SALOME_SWIG_WITHOUTIHM/omnipatch.py diff --git a/src/SALOME_SWIG_WITHOUTIHM/Makefile.in b/src/SALOME_SWIG_WITHOUTIHM/Makefile.in index be103f272..f03d9431e 100755 --- a/src/SALOME_SWIG_WITHOUTIHM/Makefile.in +++ b/src/SALOME_SWIG_WITHOUTIHM/Makefile.in @@ -38,7 +38,7 @@ VPATH=.:@srcdir@:@top_srcdir@/idl LIB_SRC = #SWIG_DEF = libSALOME_Swig.i -EXPORT_PYSCRIPTS = Help.py PyInterp.py salome.py examplevtk1.py supervisionexample.py supervisiongeomexample.py salome_shared_modules.py batchmode_salome.py test_table.py test_big_table.py test_many_objects.py import_hook.py salome_test.py salome_kernel.py salome_study.py salome_iapp.py salome_ComponentGUI.py +EXPORT_PYSCRIPTS = Help.py PyInterp.py salome.py examplevtk1.py supervisionexample.py supervisiongeomexample.py salome_shared_modules.py batchmode_salome.py test_table.py test_big_table.py test_many_objects.py import_hook.py salome_test.py salome_kernel.py salome_study.py salome_iapp.py salome_ComponentGUI.py omnipatch.py EXPORT_SHAREDPYSCRIPTS=kernel_shared_modules.py diff --git a/src/SALOME_SWIG_WITHOUTIHM/kernel_shared_modules.py b/src/SALOME_SWIG_WITHOUTIHM/kernel_shared_modules.py index b218ef6d3..8de64ad3a 100755 --- a/src/SALOME_SWIG_WITHOUTIHM/kernel_shared_modules.py +++ b/src/SALOME_SWIG_WITHOUTIHM/kernel_shared_modules.py @@ -15,69 +15,8 @@ register_pattern(lambda(x):x.endswith("_Swig")) register_name("omniORB") import omniORB -register_name("CosNaming") -import CosNaming - -# Modify omniORB to use right sys.modules dictionnary -# with multi-interpreter feature -# openModule and newModule are functions of omniORB/__init__.py module -# modified to register modules to share -# Function to return a Python module for the required IDL module name -def openModule(mname, fname=None): - # Salome modification start - import sys - # Salome modification end - - if mname == "CORBA": - mod = sys.modules["omniORB.CORBA"] - elif sys.modules.has_key(mname): - mod = sys.modules[mname] - else: - mod = newModule(mname) - - # Salome modification start - import_hook.set_shared_imported(mname,mod) - # Salome modification end - - - if not hasattr(mod, "__doc__") or mod.__doc__ is None: - mod.__doc__ = "omniORB IDL module " + mname + "\n\n" + \ - "Generated from:\n\n" - - if fname is not None: - mod.__doc__ = mod.__doc__ + " " + fname + "\n" - - return mod - -# Function to create a new module, and any parent modules which do not -# already exist -def newModule(mname): - # Salome modification start - import sys - # Salome modification end - - mlist = string.split(mname, ".") - current = "" - mod = None - - for name in mlist: - current = current + name - - if sys.modules.has_key(current): - mod = sys.modules[current] - else: - newmod = imp.new_module(current) - if mod: setattr(mod, name, newmod) - sys.modules[current] = mod = newmod - - current = current + "." - - return mod -# Replace openModule and newModule by modified ones -# to take into account the sys.modules that matches -# the right one (multi-interpreter feature) -omniORB.openModule=openModule -omniORB.newModule=newModule +register_name("omnipatch") +import omnipatch # BE CAREFUL # Engines, SALOME, SALOMEDS must be imported in that order because : diff --git a/src/SALOME_SWIG_WITHOUTIHM/omnipatch.py b/src/SALOME_SWIG_WITHOUTIHM/omnipatch.py new file mode 100644 index 000000000..20addc6fa --- /dev/null +++ b/src/SALOME_SWIG_WITHOUTIHM/omnipatch.py @@ -0,0 +1,97 @@ +""" + This patch of omniORB is made to make it work with multiple interpreters + and to correct the problem of incomplete import of CORBA packages + in some situations common in SALOME + + This patch add or modify functions in omniORB module. + + In multiple interpreters context, omniORB module is meant to be shared among + all interpreters +""" +import sys,string,imp +import omniORB +# Map of partially-opened modules +_partialModules = {} +# Map of modules to share +shared_imported={} + +# Function to return a Python module for the required IDL module name +def openModule(mname, fname=None): + # Salome modification start + # Be sure to use the right module dictionnary + import sys + # Salome modification end + + if mname == "CORBA": + mod = sys.modules["omniORB.CORBA"] + + elif sys.modules.has_key(mname): + mod = sys.modules[mname] + + if _partialModules.has_key(mname): + pmod = _partialModules[mname] + mod.__dict__.update(pmod.__dict__) + del _partialModules[mname] + + elif _partialModules.has_key(mname): + mod = _partialModules[mname] + + else: + mod = newModule(mname) + + # Salome modification start + shared_imported[mname]=mod + # Salome modification end + + if not hasattr(mod, "__doc__") or mod.__doc__ is None: + mod.__doc__ = "omniORB IDL module " + mname + "\n\n" + \ + "Generated from:\n\n" + + if fname is not None: + mod.__doc__ = mod.__doc__ + " " + fname + "\n" + + return mod + +# Function to create a new module, and any parent modules which do not +# already exist +def newModule(mname): + # Salome modification start + # Be sure to use the right module dictionnary + import sys + # Salome modification end + + mlist = string.split(mname, ".") + current = "" + mod = None + + for name in mlist: + current = current + name + + if sys.modules.has_key(current): + mod = sys.modules[current] + + elif _partialModules.has_key(current): + mod = _partialModules[current] + + else: + newmod = imp.new_module(current) + if mod: setattr(mod, name, newmod) + _partialModules[current] = mod = newmod + + current = current + "." + + return mod + +# Function to update a module with the partial module store in the +# partial module map +def updateModule(mname): + if _partialModules.has_key(mname): + pmod = _partialModules[mname] + mod = sys.modules[mname] + mod.__dict__.update(pmod.__dict__) + del _partialModules[mname] + +omniORB.updateModule=updateModule +omniORB.newModule=newModule +omniORB.openModule=openModule + diff --git a/src/SALOME_SWIG_WITHOUTIHM/salome.py b/src/SALOME_SWIG_WITHOUTIHM/salome.py index e8d5d5bac..d853b2cb6 100755 --- a/src/SALOME_SWIG_WITHOUTIHM/salome.py +++ b/src/SALOME_SWIG_WITHOUTIHM/salome.py @@ -24,6 +24,7 @@ # Module : SALOME # $Header$ +import omnipatch from salome_kernel import * from salome_study import * from salome_iapp import * diff --git a/src/SALOME_SWIG_WITHOUTIHM/salome_shared_modules.py b/src/SALOME_SWIG_WITHOUTIHM/salome_shared_modules.py index 56c884176..3e53394ee 100755 --- a/src/SALOME_SWIG_WITHOUTIHM/salome_shared_modules.py +++ b/src/SALOME_SWIG_WITHOUTIHM/salome_shared_modules.py @@ -56,7 +56,8 @@ import glob,os,sys # shared_imported, patterns, register_name, register_pattern # will be shared by all Python sub interpretors -from import_hook import shared_imported +from omnipatch import shared_imported +import_hook.shared_imported=shared_imported from import_hook import patterns from import_hook import register_name from import_hook import register_pattern -- 2.39.2