谁能使用Yapsy plugin framework提供一个最小的工作示例?
最佳答案
这是一个非常简单的示例。它具有三个文件:
您可以将更多插件添加到plugins目录,此脚本将在所有插件周围循环。
http://lateral.netmanagers.com.ar/weblog/posts/BB923.html (archived)还有另一个更复杂的示例。
yapsy-example.py
from yapsy.PluginManager import PluginManager
def 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 IPlugin
class PluginOne(IPlugin):
def print_name(self):
print "This is plugin 1"
plugins \ plugin1.yapsy-plugin
[Core]
Name = Plugin 1
Module = plugin1
[Documentation]
Author = John Smith
Version = 0.1
Website = http://lotsofplugins.com
Description = My first plugin