]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Improve Python container:
authorvsr <vsr@opencascade.com>
Thu, 26 Jan 2012 09:28:17 +0000 (09:28 +0000)
committervsr <vsr@opencascade.com>
Thu, 26 Jan 2012 09:28:17 +0000 (09:28 +0000)
- 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).

src/Container/SALOME_ContainerPy.py

index ffdc6b08febbe975c737f0dbda3ec2f8ae7df13b..a51ddc4184a4736aaad35b11425394623954bd99 100755 (executable)
@@ -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
     
     #-------------------------------------------------------------------------