From: jfa Date: Tue, 13 Dec 2005 13:07:08 +0000 (+0000) Subject: PAL10310: Problem with incomplete import of python CORBA modules. X-Git-Tag: T_3_1_0pre~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=cbb24938b229e83d2f03ebd8c23a31213cc45a71;p=modules%2Fkernel.git PAL10310: Problem with incomplete import of python CORBA modules. --- diff --git a/salome_adm/unix/config_files/check_omniorb.m4 b/salome_adm/unix/config_files/check_omniorb.m4 index 1f63365bf..7a6b6fd6d 100644 --- a/salome_adm/unix/config_files/check_omniorb.m4 +++ b/salome_adm/unix/config_files/check_omniorb.m4 @@ -181,8 +181,11 @@ fi if test "x$omniORB_ok" = "xyes" then - OMNIORB_IDLCXXFLAGS="-nf -I$OMNIORB_ROOT/idl" - OMNIORB_IDLPYFLAGS="-bpython -I$OMNIORB_ROOT/idl" + OMNIORB_IDLCXXFLAGS="-nf -I${OMNIORB_ROOT}/idl" + OMNIORB_IDLPYFLAGS_1='-bpythonbe -p ${top_srcdir}/salome_adm/unix' + OMNIORB_IDLPYFLAGS_2=" -I${OMNIORB_ROOT}/idl" + OMNIORB_IDLPYFLAGS=${OMNIORB_IDLPYFLAGS_1}${OMNIORB_IDLPYFLAGS_2} + AC_SUBST(OMNIORB_IDLCXXFLAGS) AC_SUBST(OMNIORB_IDLPYFLAGS) diff --git a/salome_adm/unix/pythonbe.py b/salome_adm/unix/pythonbe.py new file mode 100644 index 000000000..85be617d1 --- /dev/null +++ b/salome_adm/unix/pythonbe.py @@ -0,0 +1,21 @@ + +pymodule_template = """\ +# DO NOT EDIT THIS FILE! +# +# Python module @module@ generated by omniidl + +import omnipatch +omnipatch.updateModule("@module@") + +# ** 1. Stub files contributing to this module + +# ** 2. Sub-modules + +# ** 3. End""" + +import omniidl_be.python +omniidl_be.python.pymodule_template=pymodule_template + +def run(tree, args): + omniidl_be.python.run(tree, args) + diff --git a/src/Container/SALOME_ContainerPy.py b/src/Container/SALOME_ContainerPy.py index 23ac0195a..0ee6b8cd0 100755 --- a/src/Container/SALOME_ContainerPy.py +++ b/src/Container/SALOME_ContainerPy.py @@ -31,13 +31,10 @@ import os import sys import string +import omnipatch # PAL10310 from omniORB import CORBA, PortableServer -# import SALOMEDS before other SALOME modules -# (if not, incomplete import done by SALOME module: no load of SALOMEDS_attributes) import SALOMEDS import Engines, Engines__POA -reload(Engines) -reload(Engines__POA) from SALOME_NamingServicePy import * from SALOME_ComponentPy import * diff --git a/src/KERNEL_PY/Makefile.in b/src/KERNEL_PY/Makefile.in index 0f9b8963e..f5f079c20 100755 --- a/src/KERNEL_PY/Makefile.in +++ b/src/KERNEL_PY/Makefile.in @@ -31,7 +31,7 @@ VPATH=.:@srcdir@:@top_srcdir@/idl @COMMENCE@ -EXPORT_PYSCRIPTS = Help.py PyInterp.py salome.py salome_shared_modules.py batchmode_salome.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 salome_shared_modules.py batchmode_salome.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/KERNEL_PY/kernel_shared_modules.py b/src/KERNEL_PY/kernel_shared_modules.py index 5be2f15f4..3dea9f995 100755 --- a/src/KERNEL_PY/kernel_shared_modules.py +++ b/src/KERNEL_PY/kernel_shared_modules.py @@ -22,73 +22,9 @@ 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 +register_name("omnipatch") +import omnipatch - 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 - -# BE CAREFUL -# Engines, SALOME, SALOMEDS must be imported in that order because : -# Engines imports SALOME_Component_idl -# SALOME imports SALOME_Session_idl and SALOME_Exception_idl which imports SALOME_Component_idl -# and SALOMEDS imports SALOMEDS_idl and SALOMEDS_Attributes_idl which imports SALOME_Exception_idl -# If SALOME is imported before Engines, that module would not be completely imported import Engines import SALOME import SALOMEDS diff --git a/src/KERNEL_PY/omnipatch.py b/src/KERNEL_PY/omnipatch.py new file mode 100644 index 000000000..20addc6fa --- /dev/null +++ b/src/KERNEL_PY/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/KERNEL_PY/salome.py b/src/KERNEL_PY/salome.py index e8d5d5bac..d853b2cb6 100755 --- a/src/KERNEL_PY/salome.py +++ b/src/KERNEL_PY/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/KERNEL_PY/salome_shared_modules.py b/src/KERNEL_PY/salome_shared_modules.py index f74680985..1029e279e 100755 --- a/src/KERNEL_PY/salome_shared_modules.py +++ b/src/KERNEL_PY/salome_shared_modules.py @@ -56,7 +56,8 @@ import glob,os,sys import import_hook # 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