1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
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.
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.
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/>.
20 from mediagoblin
import mg_globals
21 from mediagoblin
.tools
import pluginapi
24 _log
= logging
.getLogger(__name__
)
28 """This loads, configures and registers plugins
30 See plugin documentation for more details.
33 global_config
= mg_globals
.global_config
34 plugin_section
= global_config
.get('plugins', {})
36 if not plugin_section
:
37 _log
.info("No plugins to load")
40 pman
= pluginapi
.PluginManager()
42 # Go through and import all the modules that are subsections of
43 # the [plugins] section and read in the hooks.
44 for plugin_module
, config
in plugin_section
.items():
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
49 if plugin_module
.startswith('-'):
52 _log
.info("Importing plugin module: %s" % plugin_module
)
53 pman
.register_plugin(plugin_module
)
54 # If this throws errors, that's ok--it'll halt mediagoblin
56 __import__(plugin_module
)
57 plugin
= sys
.modules
[plugin_module
]
58 if hasattr(plugin
, 'hooks'):
59 pman
.register_hooks(plugin
.hooks
)
61 # Execute anything registered to the setup hook.
62 pluginapi
.hook_runall('setup')