#print liste_modules
#print modules_root_dir
+os.environ["SALOMEPATH"]=":".join(modules_root_dir.values())
if "SUPERV" in liste_modules:with_container_superv=1
-import orbmodule
# -----------------------------------------------------------------------------
#
add_python_path(os.path.join(module_root_dir,"bin","salome"))
add_python_path(os.path.join(module_root_dir,"lib",python_version,"site-packages","salome"))
add_python_path(os.path.join(module_root_dir,"lib","salome"))
+ add_python_path(os.path.join(module_root_dir,"lib",python_version,"site-packages","salome","shared_modules"))
#print "PYTHONPATH=",sys.path
+import orbmodule
+
#
# -----------------------------------------------------------------------------
#
# -----------------------------------------------------------------------------
#
-clt=None
-try:
- clt = startSalome()
-except:
+if __name__ == "__main__":
+ clt=None
+ try:
+ clt = startSalome()
+ except:
+ print
+ print
+ print "--- erreur au lancement Salome ---"
+
+ #print process_id
+
+
+ filedict='/tmp/'+os.getenv('USER')+'_SALOME_pidict'
+ #filedict='/tmp/'+os.getlogin()+'_SALOME_pidict'
+
+ fpid=open(filedict, 'w')
+ pickle.dump(process_id,fpid)
+ fpid.close()
+
print
+ print "Sauvegarde du dictionnaire des process dans ", filedict
+ print "Pour tuer les process SALOME, executer : python killSalome.py depuis"
+ print "une console, ou bien killSalome() depuis le present interpreteur,"
+ print "s'il n'est pas fermé."
print
- print "--- erreur au lancement Salome ---"
-
-#print process_id
-
-
-filedict='/tmp/'+os.getenv('USER')+'_SALOME_pidict'
-#filedict='/tmp/'+os.getlogin()+'_SALOME_pidict'
-
-fpid=open(filedict, 'w')
-pickle.dump(process_id,fpid)
-fpid.close()
-
-print
-print "Sauvegarde du dictionnaire des process dans ", filedict
-print "Pour tuer les process SALOME, executer : python killSalome.py depuis"
-print "une console, ou bien killSalome() depuis le present interpreteur,"
-print "s'il n'est pas fermé."
-print
-print "runSalome, avec l'option --killall, commence par tuer les process restants d'une execution précédente."
-print
-print "Pour lancer uniquement le GUI, executer startGUI() depuis le present interpreteur,"
-print "s'il n'est pas fermé."
-
-#
-# Impression arborescence Naming Service
-#
-
-if clt != None:
- print
- print " --- registered objects tree in Naming Service ---"
- clt.showNS()
-
+ print "runSalome, avec l'option --killall, commence par tuer les process restants d'une execution précédente."
+ print
+ print "Pour lancer uniquement le GUI, executer startGUI() depuis le present interpreteur,"
+ print "s'il n'est pas fermé."
+
+ #
+ # Impression arborescence Naming Service
+ #
+
+ if clt != None:
+ print
+ print " --- registered objects tree in Naming Service ---"
+ clt.showNS()
+
pyqt_ok=yes
fi
-if test "x$pyqt_ok" = xno -o ! -d "$PYQTDIR" -o ! -d "$PYQTDIR"/sip ; then
+version=`python -c "import qt;print qt.PYQT_VERSION"`
+case "$version" in
+ 3.2*)
+ pyqt_vers=old ;;
+ 3.3*)
+ pyqt_vers=old ;;
+ 3.4*)
+ pyqt_vers=new ;;
+ 3.5*)
+ pyqt_vers=new ;;
+ *)
+ pyqt_vers=no ;;
+esac
+
+if test "x$pyqt_ok" = xno -o ! -d "$PYQTDIR" ; then
AC_MSG_RESULT(no)
AC_MSG_WARN(pyqt not found)
else
- AC_CHECK_FILES("$PYQTDIR"/qt.py "$PYQTDIR"/libqtcmodule.so,pyqt_ok=yes,pyqt_ok=no)
- if test "x$pyqt_ok" = xno ; then
- AC_MSG_RESULT(no)
- AC_MSG_WARN(pyqt not found)
- else
- PYQT_ROOT=$PYQTDIR
- PYQT_INCLUDES="-I$PYQTDIR/sip"
- PYQT_LIBS="-L$PYQTDIR -lqtcmodule"
-
- AC_SUBST(PYQT_ROOT)
- AC_SUBST(PYQT_INCLUDES)
- AC_SUBST(PYQT_LIBS)
-
- AC_MSG_RESULT(yes)
- fi
+
+ pyqt_ok=no
+
+ if test "x$pyqt_vers" = "xold"
+ then
+ AC_CHECK_FILES("$PYQTDIR"/qt.py "$PYQTDIR"/libqtcmodule.so,pyqt_ok=yes,pyqt_ok=no)
+ if test "x$pyqt_ok" = xno -o ! -d "$PYQTDIR"/sip ; then
+ AC_MSG_RESULT(no)
+ AC_MSG_WARN(pyqt not found)
+ else
+ PYQT_ROOT=$PYQTDIR
+ PYQT_INCLUDES="-I$PYQTDIR/sip"
+ PYQT_LIBS="-L${PYTHON_PREFIX}/lib/python${PYTHON_VERSION}/site-packages -L$PYQTDIR -lqtcmodule"
+ AC_SUBST(PYQT_ROOT)
+ AC_SUBST(PYQT_INCLUDES)
+ AC_SUBST(PYQT_LIBS)
+ AC_MSG_RESULT(yes)
+ fi
+ fi
+
+ if test "x$pyqt_vers" = "xnew"
+ then
+ AC_CHECK_FILES("$PYQTDIR"/lib/qt.py "$PYQTDIR"/lib/libqtcmodule.so,pyqt_ok=yes,pyqt_ok=no)
+ if test "x$pyqt_ok" = xno ; then
+ AC_MSG_RESULT(no)
+ AC_MSG_WARN(pyqt not found)
+ else
+ PYQT_ROOT=$PYQTDIR
+ PYQT_INCLUDES="-I$PYQTDIR/sip"
+ PYQT_LIBS="-L$PYQTDIR/lib -lqtcmodule"
+ AC_SUBST(PYQT_ROOT)
+ AC_SUBST(PYQT_INCLUDES)
+ AC_SUBST(PYQT_LIBS)
+ AC_MSG_RESULT(yes)
+ fi
+ fi
fi
AC_ARG_WITH(pyuic,
else
PYQT_SIPS=${PYQT_SIPS}
fi
- PYQT_LIBS="-L${PYTHON_PREFIX}/lib/python${PYTHON_VERSION}/site-packages ${PYQT_LIBS}"
fi
AC_SUBST(PYUIC)
AC_SUBST(PYQT_SIPS)
-AC_SUBST(PYQT_LIBS)
-
-
AC_MSG_RESULT(for pyqt: $pyqt_ok)
-from SALOME_utilities import *
-
-"""
"""
-MESSAGE( "Module salome_shared_modules" )
-
-modules={}
-try:
- # We try to import PyQt module. If present we import it
- # as a "shared" module
- import qt
- modules["qt"]=qt.__dict__
-except:
- pass
-
-# We keep in modules a copy of dictionnary modules
-# that need to be imported only once in multi-study context
-
-# Specific case : omniORB
-import omniORB
-modules["omniORB"]=omniORB.__dict__.copy()
-import omniORB.CORBA
-modules["omniORB.CORBA"]=omniORB.CORBA.__dict__.copy()
-modules["CORBA"]=modules["omniORB.CORBA"]
-import CosNaming
-modules["CosNaming"]=CosNaming.__dict__.copy()
-# end omniORB
-
-#
-# We search all Python CORBA (omniorb) modules.
-# A Python CORBA module has 2 associated Python packages
-# These packages are named : <module_name> and <module_name>__POA
-#
-
-#
-# SALOMEDS must be imported first, at least before any CORBA module
-# that references it.
-# It seems that import order of related CORBA modules is important
-# Perhaps, it's not sufficient so you should complete the list ???
-#
-import SALOMEDS
-import Engines
+This module with help of import_hook and *_shared_modules
+filters imports when using the embedded Python interpretor.
+
+Some imports can't be done more than once.
+This is related to the multi study feature that is implemented
+by using the Python multi interpreter feature.
+Some modules register objects or classes by calling modules
+implemented in C. These operations can't be done multiple times.
+So it's very important to control these imports.
+
+Examples:
+ - PyQt : import qt calls a C module to register classes
+ - OmniORB : import *_idl calls a C module to register CORBA interfaces
+
+Usage:
+ - First : the module salome_shared_modules is imported by main Python interpretor.
+ It will keep a dictionnary and a list that are shared among all
+ the subinterpretors and imports import_hook module that replaces
+ the standard import mechanism par one that prevents more than one import
+ for some modules identified by name (call register_name) or by a
+ validator (call register_pattern).
+
+ Calls to register_name and register_pattern are done in modules named *_shared_modules
+ that could be found in the path SALOMEPATH
+"""
import glob,os,sys
-repertoire=os.path.dirname(__file__)
-path=[repertoire,]
+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 import_hook import patterns
+from import_hook import register_name
+from import_hook import register_pattern
-# KERNEL is defined in KERNELCatalog
-#KERNEL_ROOT_DIR = os.getenv("KERNEL_ROOT_DIR")
-#if KERNEL_ROOT_DIR != None:
-# path.append(os.path.join(KERNEL_ROOT_DIR,"lib","python"+sys.version[:3],"site-packages","salome"))
+register_name("salome_shared_modules")
+# Get the SALOMEPATH if set or else use KERNEL_ROOT_DIR that should be set.
+salome_path=os.environ.get("SALOMEPATH",os.getenv("KERNEL_ROOT_DIR"))
-#
-import SALOME_ModuleCatalog
-from SALOME_NamingServicePy import *
-orb = CORBA.ORB_init([''], CORBA.ORB_ID)
-ns = SALOME_NamingServicePy_i(orb)
-modulecatalog = ns.Resolve('/Kernel/ModulCatalog')
-compos = []
-compos = modulecatalog.GetComponentList()
-
-for name in compos:
- print name
- MODULE_ROOT_DIR = os.getenv( name + "_ROOT_DIR" )
- print MODULE_ROOT_DIR
-
- if MODULE_ROOT_DIR != None:
- path.append(os.path.join(MODULE_ROOT_DIR,"lib","python"+sys.version[:3],"site-packages","salome"))
-
-#SALOME_ROOT_DIR = os.getenv("SALOME_ROOT_DIR")
-#if SALOME_ROOT_DIR != None:
-# path.append(os.path.join(SALOME_ROOT_DIR,"lib","python"+sys.version[:3],"site-packages","salome"))
-
-#SALOME_SITE_DIR = os.getenv("SALOME_SITE_DIR")
-#if SALOME_SITE_DIR != None:
-# SALOME_SITE_NAME = os.getenv("SALOME_SITE_NAME")
-# if SALOME_SITE_NAME != None:
-# path.append(os.path.join(SALOME_SITE_DIR,"lib","python"+sys.version[:3],"site-packages",SALOME_SITE_NAME))
-
-MESSAGE( str(path) )
+list_modules=[]
+# Import all *_shared_modules in the path and store them in list_modules
+path=salome_path.split(":")
for rep in path:
- # Add rep directory in the Python path to be able to import modules
- sys.path[:0]=[rep]
- listdir=glob.glob(os.path.join(rep,"*__POA"))
- for elem in listdir:
- if os.path.isdir(elem):
- # Found a directory (Python package) named *__POA
- module__POA=os.path.basename(elem)
- module=module__POA[:-5]
- MESSAGE( "Import CORBA module: " + module + ".\n Directory: " + os.path.abspath(elem)[:-5] )
- mod=__import__(module)
- # force the reload of CORBA module to resolve all the include relations between modules
- # specific of omniORBpy implementation (1.5)
- reload(mod)
- modules[module]=mod.__dict__.copy()
- # Now we import modules found in shared_modules directory
- r=os.path.join(rep,"shared_modules")
- MESSAGE( r )
- if os.path.isdir(r):
- sys.path[:0]=[r]
- listfich=glob.glob(os.path.join(r,"*.py"))
- MESSAGE( str(listfich) )
- for m in listfich:
- module=os.path.basename(m)[:-3]
- MESSAGE( "Import module: " + module + ".\n Location: " + os.path.abspath(m) )
- mod=__import__(module)
- modules[module]=mod.__dict__.copy()
- # Don't keep r directory in the path to not pollute it
- del sys.path[0]
+ # Import all *_shared_modules in rep
+ for f in glob.glob(os.path.join(rep,"lib","python"+sys.version[:3],"site-packages","salome","shared_modules","*_shared_modules.py")):
+ try:
+ m=__import__(os.path.splitext(os.path.basename(f))[0])
+ list_modules.append(m)
+ except:
+ pass
- # Don't keep rep directory in the path to not pollute it
- del sys.path[0]
-
-# End of CORBA modules import
-
-def import_shared_modules(sysmodules):
- """
- This function "imports" shared modules contained in modules dictionnary
- in sysmodules.
- All these modules are only copied and not completely imported (not executed)
- """
- # EDF-CCAR:
- # Problem with omniORB : omniORB creates a C Python module named _omnipy
- # this module has sub-modules : omni_func, ...
- # _omnipy is quite a package but import with Python sub-interpreters does not seem to work
- # To make it work we need to add those sub-modules in sysmodules
- import _omnipy
- sysmodules["_omnipy.omni_func"]=_omnipy.omni_func
- sysmodules["_omnipy.poa_func"]=_omnipy.poa_func
- sysmodules["_omnipy.poamanager_func"]=_omnipy.poa_func
- sysmodules["_omnipy.orb_func"]=_omnipy.orb_func
-
- import imp
-
- # All modules in the modules dictionnary are only copied, not completely imported
- for nom_module,module_dict in modules.items():
- if sysmodules.has_key(nom_module):continue
- m=imp.new_module(nom_module)
- m.__dict__.update(module_dict)
- sysmodules[nom_module]=m
+#
+# If shared modules have been imported before installing import mechanism
+# we add them to shared_imported
+#
+for name,module in sys.modules.items():
+ if import_hook.is_shared(name) and shared_imported.get(name) is None:
+ #print "Module shared added to shared_imported: ",name
+ shared_imported[name]=module