Skip to content
nacx edited this page May 2, 2012 · 23 revisions

All kahuna features are developed as a plugin, to make it easy to extend. Adding a new plugin is as simple as creating the plugin script and place it in the plugins folder.

Create a custom kahuna plugin

An example plugin can be found in kahuna/examples/skel.py and can be copied directly into the kahuna/plugins directory to see how it behaves. It can be then edited to make it perform the desired operations. The following code snipped shows the contents of the skel.py example plugin:

#!/usr/bin/env jython

# This is an example plugin that can be used as a
# skeleton for new plugins.
# To test it just rename it as desired, place it in the
# kahuna/plugins folder and run kahuna. You will see the
# new plugin in the help.

# The documentation string in the plugin class will be used to
# print the help of the plugin.

from kahuna.abstract import AbsPlugin


class SkeletonPlugin(AbsPlugin):
    """ An example plugin that prints dummy messages. """
    def __init__(self):
        pass

    # Public methods will be considered plugin commands.
    # The name of the command will be the method name.
    # The documentation string in command methods will be used to
    # print the help of the command.
    # The arguments are the options given to the command itself
    def dummy(self, args):
        """ Prints a dummy message. """
        print "This is the print_handler in the example plugin"


# Each plugin must provide a load method at module level that will be
# used to instantiate the plugin
def load():
    """ Loads the current plugin. """
    return SkeletonPlugin()

As you can see, it is quite easy to create a plugin. There are currently two requirements:

  • The plugin script must have a method called load which takes no arguments and returns a plugin instance:
def load():
    """ Loads the current plugin. """
    return SkeletonPlugin()
  • The plugin class must inherit AbsPlugin.
from kahuna.abstract import AbsPlugin

class SkeletonPlugin(AbsPlugin):

Once the plugin script has been written, it just needs to be placed in the kahuna/plugins folder. Having done this, invoking kahuna without parameters should show the plugin help in the output:

$ kahuna
Usage: kahuna <plugin> <command> [<options>]
The following plugins are available:
(...)
 An example plugin that prints dummy messages. 
   skel dummy	 Prints a dummy message.
(...)

As you can see, the output shows the new skel plugin (which name is the name of the plugin script) and its help.

That's it!

Clone this wiki locally