1 # Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
22 # File : salome_shared_modules.py
25 from SALOME_utilities import *
29 MESSAGE( "Module salome_shared_modules" )
33 # We try to import PyQt module. If present we import it
34 # as a "shared" module
36 modules["qt"]=qt.__dict__
40 # We keep in modules a copy of dictionnary modules
41 # that need to be imported only once in multi-study context
43 # Specific case : omniORB
45 modules["omniORB"]=omniORB.__dict__.copy()
47 modules["omniORB.CORBA"]=omniORB.CORBA.__dict__.copy()
48 modules["CORBA"]=modules["omniORB.CORBA"]
50 modules["CosNaming"]=CosNaming.__dict__.copy()
54 # We search all Python CORBA (omniorb) modules.
55 # A Python CORBA module has 2 associated Python packages
56 # These packages are named : <module_name> and <module_name>__POA
60 # SALOMEDS must be imported first, at least before any CORBA module
62 # It seems that import order of related CORBA modules is important
63 # Perhaps, it's not sufficient so you should complete the list ???
70 repertoire=os.path.dirname(__file__)
73 SALOME_ROOT_DIR = os.getenv("SALOME_ROOT_DIR")
74 if SALOME_ROOT_DIR != None:
75 path.append(os.path.join(SALOME_ROOT_DIR,"lib","python"+sys.version[:3],"site-packages","salome"))
77 SALOME_SITE_DIR = os.getenv("SALOME_SITE_DIR")
78 if SALOME_SITE_DIR != None:
79 SALOME_SITE_NAME = os.getenv("SALOME_SITE_NAME")
80 if SALOME_SITE_NAME != None:
81 path.append(os.path.join(SALOME_SITE_DIR,"lib","python"+sys.version[:3],"site-packages",SALOME_SITE_NAME))
84 # os.path.join(repertoire,"..","lib","python"+sys.version[:3],"site-packages","salome"),
85 # os.path.join(SALOME_ROOT_DIR,"lib","python"+sys.version[:3],"site-packages","salome"),
86 # os.path.join(SALOME_SITE_DIR,"lib","python"+sys.version[:3],"site-packages","salome"),
92 # Add rep directory in the Python path to be able to import modules
94 listdir=glob.glob(os.path.join(rep,"*__POA"))
96 if os.path.isdir(elem):
97 # Found a directory (Python package) named *__POA
98 module__POA=os.path.basename(elem)
99 module=module__POA[:-5]
100 MESSAGE( "Import CORBA module: " + module + ".\n Directory: " + os.path.abspath(elem)[:-5] )
101 mod=__import__(module)
102 # force the reload of CORBA module to resolve all the include relations between modules
103 # specific of omniORBpy implementation (1.5)
105 modules[module]=mod.__dict__.copy()
106 # Now we import modules found in shared_modules directory
107 r=os.path.join(rep,"shared_modules")
111 listfich=glob.glob(os.path.join(r,"*.py"))
112 MESSAGE( str(listfich) )
114 module=os.path.basename(m)[:-3]
115 MESSAGE( "Import module: " + module + ".\n Location: " + os.path.abspath(m) )
116 mod=__import__(module)
117 modules[module]=mod.__dict__.copy()
118 # Don't keep r directory in the path to not pollute it
121 # Don't keep rep directory in the path to not pollute it
124 # End of CORBA modules import
126 def import_shared_modules(sysmodules):
128 This function "imports" shared modules contained in modules dictionnary
130 All these modules are only copied and not completely imported (not executed)
133 # Problem with omniORB : omniORB creates a C Python module named _omnipy
134 # this module has sub-modules : omni_func, ...
135 # _omnipy is quite a package but import with Python sub-interpreters does not seem to work
136 # To make it work we need to add those sub-modules in sysmodules
138 sysmodules["_omnipy.omni_func"]=_omnipy.omni_func
139 sysmodules["_omnipy.poa_func"]=_omnipy.poa_func
140 sysmodules["_omnipy.poamanager_func"]=_omnipy.poa_func
141 sysmodules["_omnipy.orb_func"]=_omnipy.orb_func
145 # All modules in the modules dictionnary are only copied, not completely imported
146 for nom_module,module_dict in modules.items():
147 if sysmodules.has_key(nom_module):continue
148 m=imp.new_module(nom_module)
149 m.__dict__.update(module_dict)
150 sysmodules[nom_module]=m