Files
deluge/src/delugeplugins.py

99 lines
2.8 KiB
Python
Raw Normal View History

2007-01-09 00:37:57 +00:00
#!/usr/bin/env python
2007-01-08 19:38:19 +00:00
#
# delugeplugins.py
#
# Copyright (C) Zach Tibbitts 2006 <zach@collegegeek.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, write to:
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
2007-01-09 00:37:57 +00:00
import os
2007-01-08 19:38:19 +00:00
class PluginManager:
2007-02-14 22:43:48 +00:00
def __init__(self, deluge_core, deluge_interface):
2007-01-09 00:37:57 +00:00
self.plugin_dirs = []
2007-02-14 22:43:48 +00:00
self.available_plugins = {}
self.enabled_plugins = {}
self.core = deluge_core
self.interface = deluge_interface
2007-01-09 00:37:57 +00:00
def add_plugin_dir(self, directory):
self.plugin_dirs.append(directory)
def scan_for_plugins(self):
register_plugin = self.register_plugin
for folder in self.plugin_dirs:
plugin_folders = os.listdir(folder)
for plugin in plugin_folders:
2007-02-14 22:43:48 +00:00
if os.path.isfile(folder + "/" + plugin + "/plugin.py"):
2007-02-15 00:41:22 +00:00
self.path = folder + "/" + plugin
2007-02-14 22:43:48 +00:00
execfile(folder + "/" + plugin + "/plugin.py")
def get_available_plugins(self):
return self.available_plugins.keys()
def get_plugin(self, name):
return self.available_plugins[name]
def enable_plugin(self, name):
2007-02-15 00:41:22 +00:00
self.enabled_plugins[name] = self.available_plugins[name]['class'](
self.available_plugins[name]['path'], self.core, self.interface)
2007-02-14 22:43:48 +00:00
def get_enabled_plugins(self):
return self.enabled_plugins.keys()
def disable_plugin(self, name):
self.enabled_plugins[name].unload()
self.enabled_plugins.pop(name)
2007-02-15 00:41:22 +00:00
def configure_plugin(self, name):
print "configuring", name
self.enabled_plugins[name].configure()
2007-02-14 22:43:48 +00:00
def update_active_plugins(self):
for name in self.enabled_plugins.keys():
self.enabled_plugins[name].update()
2007-01-09 00:37:57 +00:00
def register_plugin(self,
name,
plugin_class,
version,
description,
config=False,
default=False,
requires=None,
interface=None,
required_plugins=None):
2007-02-14 22:43:48 +00:00
self.available_plugins[name] = {'class': plugin_class,
'version': version,
'description': description,
'config': config,
'default': default,
'requires': requires,
'interface': interface,
2007-02-15 00:41:22 +00:00
'req plugins': required_plugins,
'path': self.path}
2007-01-09 00:37:57 +00:00
## Few lines of code to test functionality
if __name__ == "__main__":
p = PluginManager()
p.add_plugin_dir("plugins/")
p.scan_for_plugins()
for x in p.plugins:
print x
for y in p.plugins[x]:
2007-02-14 22:43:48 +00:00
print "\t", y