]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
PAL 14087
authorprascle <prascle>
Fri, 1 Dec 2006 09:30:15 +0000 (09:30 +0000)
committerprascle <prascle>
Fri, 1 Dec 2006 09:30:15 +0000 (09:30 +0000)
src/KERNEL_PY/import_hook.py

index e3e744a81cf8744ee5898062c0b35fb94fe8bec4..b8687498c35babc044bab7866c245b6c7c19380f 100755 (executable)
@@ -110,6 +110,17 @@ def set_shared_imported(name,module):
     shared_imported[name]=module
     #print "Module %s shared registered" % name,module
 
+def import_module(partname, fqname, parent):
+    """ Try to import module fqname
+        It's parent is module parent and has name partname
+    """
+    try:
+       m = sys.modules[fqname]
+    except KeyError:
+       pass
+    else:
+       return m
+
 def ensure_fromlist(m, fromlist, recursive=0):
     """ Return the real modules list to be imported
     """
@@ -123,10 +134,16 @@ def ensure_fromlist(m, fromlist, recursive=0):
                     pass
                 else:
                     l.extend(ensure_fromlist(m, all, 1))
-        else:
+        elif hasattr(m,sub):
             submod=getattr(m,sub)
             if type(submod) == type(sys):
                l.append(("%s.%s" % (m.__name__, sub),submod))
+        else:
+            subname="%s.%s" % (m.__name__, sub)
+            submod = import_module(sub, subname, m)
+            if not submod:
+               raise ImportError, "No module named " + subname
+            l.append((subname,submod))
     return l
 
 def import_hook(name, globals=None, locals=None, fromlist=None):