Merge remote-tracking branch 'refs/remotes/merge-requests/47'
[mediagoblin.git] / mediagoblin / init / plugins / __init__.py
CommitLineData
29b6f917
WKG
1# GNU MediaGoblin -- federated, autonomous media hosting
2# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU Affero General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU Affero General Public License for more details.
13#
14# You should have received a copy of the GNU Affero General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17import logging
05e007c1 18import sys
29b6f917
WKG
19
20from mediagoblin import mg_globals
21from mediagoblin.tools import pluginapi
22
23
24_log = logging.getLogger(__name__)
25
26
27def setup_plugins():
28 """This loads, configures and registers plugins
29
30 See plugin documentation for more details.
31 """
32
33 global_config = mg_globals.global_config
34 plugin_section = global_config.get('plugins', {})
35
36 if not plugin_section:
37 _log.info("No plugins to load")
38 return
39
05e007c1 40 pman = pluginapi.PluginManager()
29b6f917
WKG
41
42 # Go through and import all the modules that are subsections of
05e007c1 43 # the [plugins] section and read in the hooks.
29b6f917 44 for plugin_module, config in plugin_section.items():
05d8f314
WKG
45 # Skip any modules that start with -. This makes it easier for
46 # someone to tweak their configuration so as to not load a
47 # plugin without having to remove swaths of plugin
48 # configuration.
49 if plugin_module.startswith('-'):
50 continue
51
29b6f917 52 _log.info("Importing plugin module: %s" % plugin_module)
05e007c1 53 pman.register_plugin(plugin_module)
29b6f917
WKG
54 # If this throws errors, that's ok--it'll halt mediagoblin
55 # startup.
56 __import__(plugin_module)
05e007c1
WKG
57 plugin = sys.modules[plugin_module]
58 if hasattr(plugin, 'hooks'):
59 pman.register_hooks(plugin.hooks)
60
61 # Execute anything registered to the setup hook.
c5d8d301 62 pluginapi.hook_runall('setup')