Yapsy minimal example Yapsy minimal example python python

Yapsy minimal example


Here's a very simple example. It has three files:

  • plugins\plugin1.py - the plugin. This has to contain a class inherited from IPlugin.
  • plugins\plugin1.yapsy-plugin - information about the plugin.
  • yapsy-example.py - the main script. This just loads all the plugins it can find in the "plugins" directory, and calls a method on them to prove that they work.

You could add more plugins to the plugins directory, and this script would loop around them all.

There's another more complicated example at http://lateral.netmanagers.com.ar/weblog/posts/BB923.html (archived).

yapsy-example.py

from yapsy.PluginManager import PluginManagerdef main():       # Load the plugins from the plugin directory.    manager = PluginManager()    manager.setPluginPlaces(["plugins"])    manager.collectPlugins()    # Loop round the plugins and print their names.    for plugin in manager.getAllPlugins():        plugin.plugin_object.print_name()if __name__ == "__main__":    main()

plugins\plugin1.py

from yapsy.IPlugin import IPluginclass PluginOne(IPlugin):    def print_name(self):        print "This is plugin 1"

plugins\plugin1.yapsy-plugin

[Core]Name = Plugin 1Module = plugin1[Documentation]Author = John SmithVersion = 0.1Website = http://lotsofplugins.comDescription = My first plugin