diff options
author | Christopher Allan Webber <cwebber@dustycloud.org> | 2012-07-26 10:46:52 -0500 |
---|---|---|
committer | Christopher Allan Webber <cwebber@dustycloud.org> | 2012-07-26 10:46:52 -0500 |
commit | 5e9e2deee68e3368533586fe9d6efdd6fd0d007f (patch) | |
tree | 98480867161950c0549fb6a7d76d925190b53e9c /docs/source/pluginwriter/quickstart.rst | |
parent | 33e902e3b39d9f4b25280ccd15300eaca624e778 (diff) | |
parent | 05d8f314c639f30a699c63e3d4f8feae9a5ba60b (diff) | |
download | mediagoblin-5e9e2deee68e3368533586fe9d6efdd6fd0d007f.tar.lz mediagoblin-5e9e2deee68e3368533586fe9d6efdd6fd0d007f.tar.xz mediagoblin-5e9e2deee68e3368533586fe9d6efdd6fd0d007f.zip |
Merge remote-tracking branch 'refs/remotes/willkg/plugins-infrastructure-rewrite'
Diffstat (limited to 'docs/source/pluginwriter/quickstart.rst')
-rw-r--r-- | docs/source/pluginwriter/quickstart.rst | 47 |
1 files changed, 22 insertions, 25 deletions
diff --git a/docs/source/pluginwriter/quickstart.rst b/docs/source/pluginwriter/quickstart.rst index 73531381..b5a63f79 100644 --- a/docs/source/pluginwriter/quickstart.rst +++ b/docs/source/pluginwriter/quickstart.rst @@ -50,7 +50,8 @@ The inner ``sampleplugin`` directory is the Python package that holds your plugin's code. The ``__init__.py`` denotes that this is a Python package. It also -holds the plugin code. +holds the plugin code and the ``hooks`` dict that specifies which +hooks the sampleplugin uses. Step 2: README @@ -107,43 +108,39 @@ The code for ``__init__.py`` looks like this: .. code-block:: python :linenos: - :emphasize-lines: 8,19 + :emphasize-lines: 12,23 import logging from mediagoblin.tools.pluginapi import Plugin, get_config + # This creates a logger that you can use to log information to + # the console or a log file. _log = logging.getLogger(__name__) - class SamplePlugin(Plugin): - """ - This is a sample plugin class. It automatically registers itself - with MediaGoblin when this module is imported. + # This is the function that gets called when the setup + # hook fires. + def setup_plugin(): + _log.info("I've been started!") + config = get_config('sampleplugin') + if config: + _log.info('%r' % config) + else: + _log.info('There is no configuration set.') - The setup_plugin method prints configuration for this plugin if - there is any. - """ - def __init__(self): - pass - def setup_plugin(self): - _log.info("I've been started!") - config = get_config('sampleplugin') - if config: - _log.info('%r' % config) - else: - _log.info('There is no configuration set.') + # This is a dict that specifies which hooks this plugin uses. + # This one only uses one hook: setup. + hooks = { + 'setup': setup_plugin + } -Line 8 defines a class called ``SamplePlugin`` that subclasses -``Plugin`` from ``mediagoblin.tools.pluginapi``. When the class is -defined, it gets registered with MediaGoblin and MediaGoblin will then -call ``setup_plugin`` on it. +Line 12 defines the ``setup_plugin`` function. -Line 19 defines ``setup_plugin``. This gets called when MediaGoblin -starts up after it's registered all the plugins. This is where you can -do any initialization for your plugin. +Line 23 defines ``hooks``. When MediaGoblin loads this file, it sees +``hooks`` and registers all the callables with their respective hooks. Step 6: Installation and configuration |