diff options
author | Will Kahn-Greene <willg@bluesock.org> | 2012-05-16 21:04:52 -0400 |
---|---|---|
committer | Will Kahn-Greene <willg@bluesock.org> | 2012-05-16 21:04:52 -0400 |
commit | 355fd6770dce14cf45fd696cda542cb190bb42cb (patch) | |
tree | 59305574a59203f715db21bbe26ddd82a09ff0e3 /mediagoblin/tools/pluginapi.py | |
parent | 29b6f91740e68d804612ff68295020f6cfa16071 (diff) | |
download | mediagoblin-355fd6770dce14cf45fd696cda542cb190bb42cb.tar.lz mediagoblin-355fd6770dce14cf45fd696cda542cb190bb42cb.tar.xz mediagoblin-355fd6770dce14cf45fd696cda542cb190bb42cb.zip |
Update documentation for plugins
Diffstat (limited to 'mediagoblin/tools/pluginapi.py')
-rw-r--r-- | mediagoblin/tools/pluginapi.py | 53 |
1 files changed, 41 insertions, 12 deletions
diff --git a/mediagoblin/tools/pluginapi.py b/mediagoblin/tools/pluginapi.py index 194d192e..74d05def 100644 --- a/mediagoblin/tools/pluginapi.py +++ b/mediagoblin/tools/pluginapi.py @@ -29,26 +29,36 @@ Two things about things in this module: How do plugins work? ==================== -You create a Python package. In that package, you define a high-level -``__init__.py`` that either defines or imports modules that define -classes that inherit from the ``Plugin`` class. +Plugins are structured like any Python project. You create a Python package. +In that package, you define a high-level ``__init__.py`` that either defines +or imports modules that define classes that inherit from the ``Plugin`` class. + +Additionally, you want a LICENSE file that specifies the license and a +``setup.py`` that specifies the metadata for packaging your plugin. A rough +file structure could look like this:: + + myplugin/ + |- setup.py # plugin project packaging metadata + |- README # holds plugin project information + |- LICENSE # holds license information + |- myplugin/ # plugin package directory + |- __init__.py # imports myplugin.main + |- main.py # code for plugin Lifecycle ========= 1. All the modules listed as subsections of the ``plugins`` section in - the config file are imported and any ``Plugin`` subclasses are - loaded causing it to be registered with the ``PluginCache``. - -2. After all plugin modules are imported, registered plugins are - instantiated and ``setup_plugin`` is called with the configuration. + the config file are imported. This causes any ``Plugin`` subclasses in + those modules to be defined and when the classes are defined they get + automatically registered with the ``PluginCache``. +2. After all plugin modules are imported, registered plugin classes are + instantiated and ``setup_plugin`` is called for each plugin object. -How to build a plugin -===================== - -See the documentation on building plugins. + Plugins can do any setup they need to do in their ``setup_plugin`` + method. """ import logging @@ -98,6 +108,20 @@ class MetaPluginClass(type): class Plugin(object): + """Exttend this class for plugins. + + Example:: + + from mediagoblin.tools.pluginapi import Plugin + + class MyPlugin(Plugin): + ... + + def setup_plugin(self): + .... + + """ + __metaclass__ = MetaPluginClass def setup_plugin(self): @@ -111,6 +135,11 @@ def get_config(key): >>> get_config('mediagoblin.plugins.sampleplugin') {'foo': 'bar'} + >>> get_config('myplugin') + {} + >>> get_config('flatpages') + {'directory': '/srv/mediagoblin/pages', 'nesting': 1}} + """ global_config = mg_globals.global_config |