1 from SALOME_utilities import *
5 MESSAGE( "Module salome_shared_modules" )
9 # We try to import PyQt module. If present we import it
10 # as a "shared" module
12 modules["qt"]=qt.__dict__
16 # We keep in modules a copy of dictionnary modules
17 # that need to be imported only once in multi-study context
19 # Specific case : omniORB
21 modules["omniORB"]=omniORB.__dict__.copy()
23 modules["omniORB.CORBA"]=omniORB.CORBA.__dict__.copy()
24 modules["CORBA"]=modules["omniORB.CORBA"]
26 modules["CosNaming"]=CosNaming.__dict__.copy()
30 # We search all Python CORBA (omniorb) modules.
31 # A Python CORBA module has 2 associated Python packages
32 # These packages are named : <module_name> and <module_name>__POA
36 # SALOMEDS must be imported first, at least before any CORBA module
38 # It seems that import order of related CORBA modules is important
39 # Perhaps, it's not sufficient so you should complete the list ???
46 repertoire=os.path.dirname(__file__)
49 # KERNEL is defined in KERNELCatalog
50 #KERNEL_ROOT_DIR = os.getenv("KERNEL_ROOT_DIR")
51 #if KERNEL_ROOT_DIR != None:
52 # path.append(os.path.join(KERNEL_ROOT_DIR,"lib","python"+sys.version[:3],"site-packages","salome"))
56 import SALOME_ModuleCatalog
57 from SALOME_NamingServicePy import *
58 orb = CORBA.ORB_init([''], CORBA.ORB_ID)
59 ns = SALOME_NamingServicePy_i(orb)
60 modulecatalog = ns.Resolve('/Kernel/ModulCatalog')
62 compos = modulecatalog.GetComponentList()
66 MODULE_ROOT_DIR = os.getenv( name + "_ROOT_DIR" )
69 if MODULE_ROOT_DIR != None:
70 path.append(os.path.join(MODULE_ROOT_DIR,"lib","python"+sys.version[:3],"site-packages","salome"))
72 #SALOME_ROOT_DIR = os.getenv("SALOME_ROOT_DIR")
73 #if SALOME_ROOT_DIR != None:
74 # path.append(os.path.join(SALOME_ROOT_DIR,"lib","python"+sys.version[:3],"site-packages","salome"))
76 #SALOME_SITE_DIR = os.getenv("SALOME_SITE_DIR")
77 #if SALOME_SITE_DIR != None:
78 # SALOME_SITE_NAME = os.getenv("SALOME_SITE_NAME")
79 # if SALOME_SITE_NAME != None:
80 # path.append(os.path.join(SALOME_SITE_DIR,"lib","python"+sys.version[:3],"site-packages",SALOME_SITE_NAME))
85 # Add rep directory in the Python path to be able to import modules
87 listdir=glob.glob(os.path.join(rep,"*__POA"))
89 if os.path.isdir(elem):
90 # Found a directory (Python package) named *__POA
91 module__POA=os.path.basename(elem)
92 module=module__POA[:-5]
93 MESSAGE( "Import CORBA module: " + module + ".\n Directory: " + os.path.abspath(elem)[:-5] )
94 mod=__import__(module)
95 # force the reload of CORBA module to resolve all the include relations between modules
96 # specific of omniORBpy implementation (1.5)
98 modules[module]=mod.__dict__.copy()
99 # Now we import modules found in shared_modules directory
100 r=os.path.join(rep,"shared_modules")
104 listfich=glob.glob(os.path.join(r,"*.py"))
105 MESSAGE( str(listfich) )
107 module=os.path.basename(m)[:-3]
108 MESSAGE( "Import module: " + module + ".\n Location: " + os.path.abspath(m) )
109 mod=__import__(module)
110 modules[module]=mod.__dict__.copy()
111 # Don't keep r directory in the path to not pollute it
114 # Don't keep rep directory in the path to not pollute it
117 # End of CORBA modules import
119 def import_shared_modules(sysmodules):
121 This function "imports" shared modules contained in modules dictionnary
123 All these modules are only copied and not completely imported (not executed)
126 # Problem with omniORB : omniORB creates a C Python module named _omnipy
127 # this module has sub-modules : omni_func, ...
128 # _omnipy is quite a package but import with Python sub-interpreters does not seem to work
129 # To make it work we need to add those sub-modules in sysmodules
131 sysmodules["_omnipy.omni_func"]=_omnipy.omni_func
132 sysmodules["_omnipy.poa_func"]=_omnipy.poa_func
133 sysmodules["_omnipy.poamanager_func"]=_omnipy.poa_func
134 sysmodules["_omnipy.orb_func"]=_omnipy.orb_func
138 # All modules in the modules dictionnary are only copied, not completely imported
139 for nom_module,module_dict in modules.items():
140 if sysmodules.has_key(nom_module):continue
141 m=imp.new_module(nom_module)
142 m.__dict__.update(module_dict)
143 sysmodules[nom_module]=m