import os
import sys
import traceback
-import imp
+import importlib
from omniORB import CORBA, PortableServer
import SALOMEDS
import Engines, Engines__POA
ret=""
try:
if verbose(): print("try import ",componentName)
- __import__(componentName)
+ importlib.import_module(componentName)
if verbose(): print("import ",componentName," successful")
- except ImportError as e:
+ except ImportError:
#can't import python module componentName
#try to find it in python path
try:
- fp, pathname, description = imp.find_module(componentName)
- if fp:fp.close()
+ _specs = importlib.util.find_spec(componentName)
+ _module = importlib.util.module_from_spec(_specs)
+ _specs.loader.exec_module(_module)
#module file found in path
ret="Component "+componentName+": Python implementation found but it can't be loaded\n"
ret=ret+traceback.format_exc(10)
traceback.print_exc()
print("import ",componentName," not possible")
return ret
-
+
#-------------------------------------------------------------------------
def create_component_instance(self, componentName, instanceName):
comp_iors=""
ret=""
try:
- component=__import__(componentName)
+ component=importlib.import_module(componentName)
factory=getattr(component,componentName)
comp_i=factory(self._orb,
self._poa,
traceback.print_exc()
MESSAGE( "SALOME_Container_i::create_component_instance : NOT OK")
return comp_iors, ret
-
+
def create_pynode(self,nodeName,code):
try:
#
import os
import sys
-import string
+import importlib
from omniORB import CORBA, PortableServer
-import SALOMEDS
+import SALOMEDS
import Engines, Engines__POA
import salome_psutil
from SALOME_NamingServicePy import *
self._numInstance = self._numInstance +1
instanceName = nameToRegister + "_inst_" + repr(self._numInstance)
- component=__import__(componentName)
+ component=importlib.import_module(componentName)
factory=getattr(component,componentName)
comp_i=factory(self._orb, self._poa, self._this(), self._containerName,
instanceName, nameToRegister)
exec(the_command)
comp_o = comp_i._this()
return comp_o
-
+
#-------------------------------------------------------------------------
-
+
def import_component(self, componentName):
MESSAGE( "SALOME_Container_i::import_component" )
reason = ""
try:
if verbose(): print("try import %s" % componentName)
# try import component
- module=__import__(componentName)
+ module=importlib.import_module(componentName)
if verbose(): print("import %s is done successfully" % componentName)
# if import successfully, check that component is loadable
if not hasattr(module, componentName):
interfaceName = componentName
reason = self.import_component(componentName)
return reason == "", reason
-
+
#-------------------------------------------------------------------------
def create_component_instance_env(self, componentName, env):
instanceName = componentName + "_inst_" + repr(self._numInstance)
comp_iors=""
try:
- component=__import__(componentName)
+ component=importlib.import_module(componentName)
factory=getattr(component,componentName)
comp_i=factory(self._orb,
self._poa,
self._containerName,
instanceName,
componentName)
-
+
MESSAGE( "SALOME_Container_i::create_component_instance : OK")
comp_o = comp_i._this()
self._listInstances_map[instanceName] = comp_i
anEngine = self._listInstances_map[instance]
return anEngine._this()
return anEngine
-
+
#-------------------------------------------------------------------------
def create_python_service_instance(self, CompName):
return self.create_component_instance(CompName)
-
+
#-------------------------------------------------------------------------
def remove_impl(self, component):
return self._machineName
#-------------------------------------------------------------------------
-
+
def _get_machineName(self):
MESSAGE( "SALOME_ContainerPy_i::_get_MachineName" )
self._machineName = "localhost"
self._naming_service = naming_service
MESSAGE( str(Container_path) )
naming_service.Register(self._this(), Container_path)
-
+
#-------------------------------------------------------------------------
def start_impl(self, ContainerName):
break
num += 1
pass
-
+
shstr += " > "
shstr += fileName
shstr += " 2>&1 &"
-
+
#shstr += " > /tmp/"
#shstr += ContainerName
#shstr += ".log 2>&1 &"
-
+
MESSAGE( "SALOME_ContainerPy_i::start_impl " + "os.system(" + str(shstr) + ")" )
os.system( shstr )
count = 21
SALOME_ContainerPy_Gen_i.__init__(self, orb, poa, containerName)
naming_service = SALOME_Embedded_NamingService()
self._naming_service = naming_service._this()
-
+
def get_embedded_NS_if_ssl(self):
return self._naming_service
MESSAGE( str(sys.argv) )
containerName = sys.argv[1]
cpy_i = SALOME_ContainerPy_i(orb, poa, containerName)
- if verbose():print("SALOME_ContainerPy_i instance created ",cpy_i)
+ if verbose():print("SALOME_ContainerPy_i instance created ",cpy_i)
cpy_o = cpy_i._this()
if verbose():print("SALOME_ContainerPy_i instance activated ",cpy_o)
sys.stdout.flush()
The function functionName is supposed here to return a boolean value
indicating if the test is OK (True) or NOT OK (False)
"""
- moduleName = modulePath.replace('/','.')
- __import__ (moduleName)
+ moduleName = modulePath.replace('/','.')
+ import importlib
+ importlib.import_module(moduleName)
module=sys.modules[moduleName]
func = getattr(module,functionName)
tabsize = 70-len(moduleName)-len(functionName)
- print("[TEST] %s.%s %s test in progress" % (moduleName, functionName,"."*tabsize))
+ print("[TEST] %s.%s %s test in progress" % (moduleName, functionName,"."*tabsize))
ok = func()
if ( ok ):
print("[TEST] %s.%s %s OK" % (moduleName, functionName,"."*tabsize))