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_ROOT_DIR = os.getenv("KERNEL_ROOT_DIR")
50 if KERNEL_ROOT_DIR != None:
51 path.append(os.path.join(KERNEL_ROOT_DIR,"lib","python"+sys.version[:3],"site-packages","salome"))
55 import SALOME_ModuleCatalog
56 from SALOME_NamingServicePy import *
57 orb = CORBA.ORB_init([''], CORBA.ORB_ID)
58 ns = SALOME_NamingServicePy_i(orb)
59 modulecatalog = ns.Resolve('/Kernel/ModulCatalog')
61 compos = modulecatalog.GetComponentList()
65 MODULE_ROOT_DIR = os.getenv( name + "_ROOT_DIR" )
68 if MODULE_ROOT_DIR != None:
69 path.append(os.path.join(MODULE_ROOT_DIR,"lib","python"+sys.version[:3],"site-packages","salome"))
71 #SALOME_ROOT_DIR = os.getenv("SALOME_ROOT_DIR")
72 #if SALOME_ROOT_DIR != None:
73 # path.append(os.path.join(SALOME_ROOT_DIR,"lib","python"+sys.version[:3],"site-packages","salome"))
75 #SALOME_SITE_DIR = os.getenv("SALOME_SITE_DIR")
76 #if SALOME_SITE_DIR != None:
77 # SALOME_SITE_NAME = os.getenv("SALOME_SITE_NAME")
78 # if SALOME_SITE_NAME != None:
79 # path.append(os.path.join(SALOME_SITE_DIR,"lib","python"+sys.version[:3],"site-packages",SALOME_SITE_NAME))
84 # Add rep directory in the Python path to be able to import modules
86 listdir=glob.glob(os.path.join(rep,"*__POA"))
88 if os.path.isdir(elem):
89 # Found a directory (Python package) named *__POA
90 module__POA=os.path.basename(elem)
91 module=module__POA[:-5]
92 MESSAGE( "Import CORBA module: " + module + ".\n Directory: " + os.path.abspath(elem)[:-5] )
93 mod=__import__(module)
94 # force the reload of CORBA module to resolve all the include relations between modules
95 # specific of omniORBpy implementation (1.5)
97 modules[module]=mod.__dict__.copy()
98 # Now we import modules found in shared_modules directory
99 r=os.path.join(rep,"shared_modules")
103 listfich=glob.glob(os.path.join(r,"*.py"))
104 MESSAGE( str(listfich) )
106 module=os.path.basename(m)[:-3]
107 MESSAGE( "Import module: " + module + ".\n Location: " + os.path.abspath(m) )
108 mod=__import__(module)
109 modules[module]=mod.__dict__.copy()
110 # Don't keep r directory in the path to not pollute it
113 # Don't keep rep directory in the path to not pollute it
116 # End of CORBA modules import
118 def import_shared_modules(sysmodules):
120 This function "imports" shared modules contained in modules dictionnary
122 All these modules are only copied and not completely imported (not executed)
125 # Problem with omniORB : omniORB creates a C Python module named _omnipy
126 # this module has sub-modules : omni_func, ...
127 # _omnipy is quite a package but import with Python sub-interpreters does not seem to work
128 # To make it work we need to add those sub-modules in sysmodules
130 sysmodules["_omnipy.omni_func"]=_omnipy.omni_func
131 sysmodules["_omnipy.poa_func"]=_omnipy.poa_func
132 sysmodules["_omnipy.poamanager_func"]=_omnipy.poa_func
133 sysmodules["_omnipy.orb_func"]=_omnipy.orb_func
137 # All modules in the modules dictionnary are only copied, not completely imported
138 for nom_module,module_dict in modules.items():
139 if sysmodules.has_key(nom_module):continue
140 m=imp.new_module(nom_module)
141 m.__dict__.update(module_dict)
142 sysmodules[nom_module]=m