From: vsr Date: Thu, 26 Jan 2012 09:28:17 +0000 (+0000) Subject: Improve Python container: X-Git-Tag: V6_5_0a1~56 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4fd6ec5d43f0b05db1fa34dba3b175d79edacc52;p=modules%2Fkernel.git Improve Python container: - load_component_Library() function returns now reason of the failure if it can't load the component module - avoid raising an exception when triyng loading unexistent or inappropriate module (for instance, if module is not a Python, but C++ one). --- diff --git a/src/Container/SALOME_ContainerPy.py b/src/Container/SALOME_ContainerPy.py index ffdc6b08f..a51ddc418 100755 --- a/src/Container/SALOME_ContainerPy.py +++ b/src/Container/SALOME_ContainerPy.py @@ -168,17 +168,24 @@ class SALOME_ContainerPy_i (Engines__POA.Container): def import_component(self, componentName): MESSAGE( "SALOME_Container_i::import_component" ) - ret=0 + reason = "" try: - if verbose(): print "try import ",componentName + if verbose(): print "try import %s" % componentName + # try import component module=__import__(componentName) - if verbose(): print "import ",componentName," successful" - ret=1 + if verbose(): print "import %s is done successfully" % componentName + # if import successfully, check that component is loadable + if not hasattr(module, componentName): + reason = "module %s is not loadable" % componentName + print reason + pass + pass except: import traceback + print "cannot import %s" % componentName traceback.print_exc() - print "import ",componentName," not possible" - return ret + reason = "cannot import %s" % componentName + return reason #------------------------------------------------------------------------- @@ -187,7 +194,8 @@ class SALOME_ContainerPy_i (Engines__POA.Container): ret = 0 instanceName = componentName + "_inst_" + `self._numInstance` interfaceName = componentName - return self.import_component(componentName), "" + reason = self.import_component(componentName) + return reason == "", reason #-------------------------------------------------------------------------