任何人都可以使用Yapsy plugin framework提供最小的工作示例吗?
答案 0 :(得分:44)
这是一个非常简单的例子。它有三个文件:
你可以在插件目录中添加更多的插件,这个脚本会循环遍历它们。
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()
<强>插件\ plugin1.py 强>
from yapsy.IPlugin import IPlugin
class PluginOne(IPlugin):
def print_name(self):
print "This is plugin 1"
<强>插件\ plugin1.yapsy-插件强>
[Core]
Name = Plugin 1
Module = plugin1
[Documentation]
Author = John Smith
Version = 0.1
Website = http://lotsofplugins.com
Description = My first plugin