changeset 3829:8fea1d0ca8ac

plugins: don't rely on modules attribute
author Johannes Berg <johannes AT sipsolutions DOT net>
date Fri, 11 Jul 2008 16:15:04 +0200
parents d125f175fc2e
children 3af779616368
files MoinMoin/util/pysupport.py MoinMoin/wikiutil.py
diffstat 2 files changed, 23 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/util/pysupport.py	Fri Jul 11 13:40:52 2008 +0200
+++ b/MoinMoin/util/pysupport.py	Fri Jul 11 16:15:04 2008 +0200
@@ -20,6 +20,22 @@
         return 0
 
 
+def getPluginModules(packagedir):
+    """
+    Return a list of plugin modules for a given plugin package dir,
+    omitting any that start with an underscore.
+    """
+    import os, re
+
+    pyre = re.compile(r"^([^_].*)\.py$")
+    dirlist = os.listdir(packagedir)
+    matches = [pyre.match(fn) for fn in dirlist]
+    modules = [match.group(1) for match in matches if match]
+
+    modules.sort()
+    return modules
+
+
 def getPackageModules(packagefile):
     """ Return a list of modules for a package, omitting any modules
         starting with an underscore.
--- a/MoinMoin/wikiutil.py	Fri Jul 11 13:40:52 2008 +0200
+++ b/MoinMoin/wikiutil.py	Fri Jul 11 16:15:04 2008 +0200
@@ -1175,18 +1175,22 @@
     @return: module names
     """
     # Wiki plugins are located in wikiconfig.plugin module
-    modulename = '%s.plugin.%s' % (cfg.siteid, kind)
+    modulename = '%s.plugin' % (cfg.siteid, )
 
     # short-cut if we've loaded the list already
     # (or already failed to load it)
     if kind in cfg._site_plugin_lists:
         return cfg._site_plugin_lists[kind]
 
+    import sys
     try:
-        plugins = pysupport.importName(modulename, "modules")
+        module = pysupport.importName(modulename, kind)
+        packagepath = os.path.dirname(module.__file__)
+        plugins = pysupport.getPluginModules(packagepath)
+
         cfg._site_plugin_lists[kind] = plugins
         return plugins
-    except ImportError:
+    except AttributeError:
         cfg._site_plugin_lists[kind] = []
         return []