commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnue] r7609 - trunk/gnue-common/src/apps


From: reinhard
Subject: [gnue] r7609 - trunk/gnue-common/src/apps
Date: Fri, 17 Jun 2005 07:17:52 -0500 (CDT)

Author: reinhard
Date: 2005-06-17 07:17:51 -0500 (Fri, 17 Jun 2005)
New Revision: 7609

Modified:
   trunk/gnue-common/src/apps/plugin.py
Log:
Added option to list function to suppress call of __initplugin__. Do not regard
the root directory given to list function as potential plugin itself.


Modified: trunk/gnue-common/src/apps/plugin.py
===================================================================
--- trunk/gnue-common/src/apps/plugin.py        2005-06-17 08:15:45 UTC (rev 
7608)
+++ trunk/gnue-common/src/apps/plugin.py        2005-06-17 12:17:51 UTC (rev 
7609)
@@ -109,12 +109,13 @@
 # List all available plugins
 # -----------------------------------------------------------------------------
 
-def list (base, identifier):
+def list (base, identifier, try_to_init = True):
   """
   List all available plugins.
 
   @param base: Name of the package that contains the plugins.
   @param identifier: Identifier that a plugin must define to qualify as module.
+  @param try_to_init: If set to False, __initplugin__ is not called.
   @return: A dictionary with the available plugin module names as keys and
       either the loaded module or the exception info tuple of the exception
       raised when trying to import the module as values.
@@ -128,7 +129,7 @@
   _identifier = identifier.encode ()
 
   # Now recursively list the plugins
-  return __list (_base, _identifier)
+  return __list (_base, _identifier, try_to_init, True)
 
 
 # -----------------------------------------------------------------------------
@@ -217,7 +218,7 @@
 # Recursively list all plugins
 # -----------------------------------------------------------------------------
 
-def __list (base, identifier):
+def __list (base, identifier, try_to_init, top):
 
   global __failed
 
@@ -235,20 +236,21 @@
     # This is not a plugin, ignore it
     return {}
 
-  if hasattr (m, identifier):
-    # This is already a plugin, no need to go deeper
-    if hasattr (m, '__initplugin__'):
-      try:
-        m.__initplugin__ ()
-      except:
-        __failed [base] = sys.exc_info ()
-        return {base: __failed [base]}
-    return {base: m}
+  if not top:
+    if hasattr (m, identifier):
+      # This is already a plugin, no need to go deeper
+      if try_to_init and hasattr (m, '__initplugin__'):
+        try:
+          m.__initplugin__ ()
+        except:
+          __failed [base] = sys.exc_info ()
+          return {base: __failed [base]}
+      return {base: m}
 
   # List all submodules
   result = {}
   for sub in __modules (m, False):
-    result.update (__list (base + '.' + sub, identifier))
+    result.update (__list (base + '.' + sub, identifier, try_to_init, False))
   return result
 
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]