changeset 2381:b8b87daf7cc4

don't require all plugins to be in the data/plugin dir, cache modules list
author Johannes Berg <johannes AT sipsolutions DOT net>
date Tue, 17 Jul 2007 13:23:10 +0200
parents 0d04c8c82eb6
children 878cc77c74ea
files MoinMoin/config/multiconfig.py MoinMoin/wikiutil.py
diffstat 2 files changed, 16 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/config/multiconfig.py	Tue Jul 17 12:34:34 2007 +0200
+++ b/MoinMoin/config/multiconfig.py	Tue Jul 17 13:23:10 2007 +0200
@@ -205,6 +205,9 @@
 class DefaultConfig:
     """ default config values """
 
+    # internal dict for plugin `modules' lists
+    _site_plugin_lists = {}
+
     # setting DesktopEdition = True gives all local users special powers - ONLY use for MMDE style usage!
     DesktopEdition = False
 
--- a/MoinMoin/wikiutil.py	Tue Jul 17 12:34:34 2007 +0200
+++ b/MoinMoin/wikiutil.py	Tue Jul 17 13:23:10 2007 +0200
@@ -1090,16 +1090,25 @@
 def wikiPlugins(kind, cfg):
     """ Gets a list of modules in data/plugin/'kind'
 
-    Require valid plugin directory. e.g missing 'parser' directory or
-    missing '__init__.py' file will raise errors.
-
     @param kind: what kind of modules we look for
     @rtype: list
     @return: module names
     """
     # Wiki plugins are located in wikiconfig.plugin module
     modulename = '%s.plugin.%s' % (cfg.siteid, kind)
-    return pysupport.importName(modulename, "modules")
+
+    # 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]
+
+    try:
+        plugins = pysupport.importName(modulename, "modules")
+        cfg._site_plugin_lists[kind] = plugins
+        return plugins
+    except ImportError:
+        cfg._site_plugin_lists[kind] = []
+        return []
 
 
 def getPlugins(kind, cfg):