From 05d8f314c639f30a699c63e3d4f8feae9a5ba60b Mon Sep 17 00:00:00 2001 From: Will Kahn-Greene Date: Tue, 17 Jul 2012 21:14:45 -0400 Subject: [PATCH] [Issue 466] Implement e-z plugin disabling --- docs/source/siteadmin/plugins.rst | 32 ++++++++++++++++++++++++++++ mediagoblin/init/plugins/__init__.py | 7 ++++++ mediagoblin/tests/test_pluginapi.py | 20 +++++++++++++++++ 3 files changed, 59 insertions(+) diff --git a/docs/source/siteadmin/plugins.rst b/docs/source/siteadmin/plugins.rst index 41f2970f..f5a78da7 100644 --- a/docs/source/siteadmin/plugins.rst +++ b/docs/source/siteadmin/plugins.rst @@ -135,3 +135,35 @@ For plugins that you install with pip, you can upgrade them with pip:: pip install -U The ``-U`` tells pip to upgrade the package. + + +Troubleshooting plugins +======================= + +Sometimes plugins just don't work right. When you're having problems +with plugins, think about the following: + +1. Check the log files. + + Some plugins will log errors to the log files and you can use that + to diagnose the problem. + +2. Try running MediaGoblin without that plugin. + + It's easy to disable a plugin from MediaGoblin. Add a ``-`` to the + name in your config file. + + For example, change:: + + [[mediagoblin.plugins.flatpages]] + + to:: + + [[-mediagoblin.plugins.flatpages]] + + That'll prevent the ``mediagoblin.plugins.flatpages`` plugin from + loading. + +3. If it's a core plugin that comes with MediaGoblin, ask us for help! + + If it's a plugin you got from somewhere else, ask them for help! diff --git a/mediagoblin/init/plugins/__init__.py b/mediagoblin/init/plugins/__init__.py index 4ac7a140..cdf9b5ad 100644 --- a/mediagoblin/init/plugins/__init__.py +++ b/mediagoblin/init/plugins/__init__.py @@ -42,6 +42,13 @@ def setup_plugins(): # Go through and import all the modules that are subsections of # the [plugins] section and read in the hooks. for plugin_module, config in plugin_section.items(): + # Skip any modules that start with -. This makes it easier for + # someone to tweak their configuration so as to not load a + # plugin without having to remove swaths of plugin + # configuration. + if plugin_module.startswith('-'): + continue + _log.info("Importing plugin module: %s" % plugin_module) pman.register_plugin(plugin_module) # If this throws errors, that's ok--it'll halt mediagoblin diff --git a/mediagoblin/tests/test_pluginapi.py b/mediagoblin/tests/test_pluginapi.py index 8c9c6a04..315a95da 100644 --- a/mediagoblin/tests/test_pluginapi.py +++ b/mediagoblin/tests/test_pluginapi.py @@ -153,3 +153,23 @@ def test_same_plugin_twice(): # Make sure _setup_plugin_called was called once import mediagoblin.plugins.sampleplugin eq_(mediagoblin.plugins.sampleplugin._setup_plugin_called, 1) + + +@with_cleanup() +def test_disabled_plugin(): + """Run setup_plugins with a single working plugin twice""" + cfg = build_config([ + ('mediagoblin', {}, []), + ('plugins', {}, [ + ('-mediagoblin.plugins.sampleplugin', {}, []), + ]) + ]) + + mg_globals.app_config = cfg['mediagoblin'] + mg_globals.global_config = cfg + + pman = pluginapi.PluginManager() + setup_plugins() + + # Make sure we didn't load the plugin + eq_(len(pman.plugins), 0) -- 2.25.1