mirror of
https://git.deluge-torrent.org/deluge
synced 2025-09-22 17:48:31 +00:00
Change some plugin stuff and add an example plugin
This commit is contained in:
parent
8025889598
commit
703e9def05
10 changed files with 271 additions and 64 deletions
|
@ -115,7 +115,11 @@ class PluginManagerBase:
|
||||||
for name in egg.get_entry_map(self.entry_name):
|
for name in egg.get_entry_map(self.entry_name):
|
||||||
entry_point = egg.get_entry_info(self.entry_name, name)
|
entry_point = egg.get_entry_info(self.entry_name, name)
|
||||||
cls = entry_point.load()
|
cls = entry_point.load()
|
||||||
instance = cls(self, plugin_name.replace("-", "_"))
|
try:
|
||||||
|
instance = cls(plugin_name.replace("-", "_"))
|
||||||
|
except Exception, e:
|
||||||
|
log.error("Unable to instantiate plugin!")
|
||||||
|
log.exception(e)
|
||||||
instance.enable()
|
instance.enable()
|
||||||
plugin_name = plugin_name.replace("-", " ")
|
plugin_name = plugin_name.replace("-", " ")
|
||||||
self.plugins[plugin_name] = instance
|
self.plugins[plugin_name] = instance
|
||||||
|
|
|
@ -24,35 +24,36 @@
|
||||||
# Boston, MA 02110-1301, USA.
|
# Boston, MA 02110-1301, USA.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
|
|
||||||
from deluge.plugins.init import PluginBase
|
from deluge.plugins.init import PluginInitBase
|
||||||
|
|
||||||
class CorePlugin(PluginBase):
|
class CorePlugin(PluginInitBase):
|
||||||
def __init__(self, plugin_api, plugin_name):
|
def __init__(self, plugin_name):
|
||||||
# Load the Core portion of the plugin
|
# Load the Core portion of the plugin
|
||||||
try:
|
try:
|
||||||
from core import Core
|
from core import Core
|
||||||
self.plugin = Core(plugin_api, plugin_name)
|
self.plugin = Core(plugin_name)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
log.debug("Did not load a Core plugin: %s", e)
|
log.error("Failed to load core plugin %s!", plugin_name)
|
||||||
|
log.exception(e)
|
||||||
|
|
||||||
class GtkUIPlugin(PluginBase):
|
class GtkUIPlugin(PluginInitBase):
|
||||||
def __init__(self, plugin_api, plugin_name):
|
def __init__(self, plugin_name):
|
||||||
# Load the GtkUI portion of the plugin
|
# Load the GtkUI portion of the plugin
|
||||||
try:
|
try:
|
||||||
from gtkui import GtkUI
|
from gtkui import GtkUI
|
||||||
self.plugin = GtkUI(plugin_api, plugin_name)
|
self.plugin = GtkUI(plugin_name)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
log.debug("Did not load a GtkUI plugin: %s", e)
|
log.error("Failed to load gtkui plugin %s!", plugin_name)
|
||||||
|
log.exception(e)
|
||||||
|
|
||||||
class WebUIPlugin(PluginBase):
|
class WebUIPlugin(PluginInitBase):
|
||||||
def __init__(self, plugin_api, plugin_name):
|
def __init__(self, plugin_name):
|
||||||
# Load the GtkUI portion of the plugin
|
# Load the WebUI portion of the plugin
|
||||||
try:
|
try:
|
||||||
from webui import WebUI
|
from webui import WebUI
|
||||||
self.plugin = WebUI(plugin_api, plugin_name)
|
self.plugin = WebUI(plugin_name)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
log.debug("Did not load a WebUI plugin: %s", e)
|
log.error("Failed to load webui plugin %s!", plugin_name)
|
||||||
|
log.exception(e)
|
||||||
|
|
35
deluge/plugins/example/example/__init__.py
Normal file
35
deluge/plugins/example/example/__init__.py
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
#
|
||||||
|
# __init__.py
|
||||||
|
#
|
||||||
|
# Copyright (C) 2009 Andrew Resch <andrewresch@gmail.com>
|
||||||
|
#
|
||||||
|
# Deluge is free software.
|
||||||
|
#
|
||||||
|
# You may redistribute it and/or modify it under the terms of the
|
||||||
|
# GNU General Public License, as published by the Free Software
|
||||||
|
# Foundation; either version 3 of the License, or (at your option)
|
||||||
|
# any later version.
|
||||||
|
#
|
||||||
|
# deluge 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 deluge. If not, write to:
|
||||||
|
# The Free Software Foundation, Inc.,
|
||||||
|
# 51 Franklin Street, Fifth Floor
|
||||||
|
# Boston, MA 02110-1301, USA.
|
||||||
|
#
|
||||||
|
|
||||||
|
from deluge.log import LOG as log
|
||||||
|
from deluge.plugins.init import PluginInitBase
|
||||||
|
|
||||||
|
class CorePlugin(PluginInitBase):
|
||||||
|
from core import Core as _plugin_cls
|
||||||
|
|
||||||
|
class GtkUIPlugin(PluginInitBase):
|
||||||
|
from gtkui import GtkUI as _plugin_cls
|
||||||
|
|
||||||
|
class WebUIPlugin(PluginInitBase):
|
||||||
|
from webui import WebUI as _plugin_cls
|
29
deluge/plugins/example/example/common.py
Normal file
29
deluge/plugins/example/example/common.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#
|
||||||
|
# common.py
|
||||||
|
#
|
||||||
|
# Copyright (C) 2009 Andrew Resch <andrewresch@gmail.com>
|
||||||
|
#
|
||||||
|
# Deluge is free software.
|
||||||
|
#
|
||||||
|
# You may redistribute it and/or modify it under the terms of the
|
||||||
|
# GNU General Public License, as published by the Free Software
|
||||||
|
# Foundation; either version 3 of the License, or (at your option)
|
||||||
|
# any later version.
|
||||||
|
#
|
||||||
|
# deluge 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 deluge. If not, write to:
|
||||||
|
# The Free Software Foundation, Inc.,
|
||||||
|
# 51 Franklin Street, Fifth Floor
|
||||||
|
# Boston, MA 02110-1301, USA.
|
||||||
|
#
|
||||||
|
|
||||||
|
import pkg_resources
|
||||||
|
import os.path
|
||||||
|
|
||||||
|
def get_resource(filename):
|
||||||
|
return pkg_resources.resource_filename("blocklist", os.path.join("data", filename))
|
44
deluge/plugins/example/example/core.py
Normal file
44
deluge/plugins/example/example/core.py
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
#
|
||||||
|
# core.py
|
||||||
|
#
|
||||||
|
# Copyright (C) 2009 Andrew Resch <andrewresch@gmail.com>
|
||||||
|
#
|
||||||
|
# Deluge is free software.
|
||||||
|
#
|
||||||
|
# You may redistribute it and/or modify it under the terms of the
|
||||||
|
# GNU General Public License, as published by the Free Software
|
||||||
|
# Foundation; either version 3 of the License, or (at your option)
|
||||||
|
# any later version.
|
||||||
|
#
|
||||||
|
# deluge 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 deluge. If not, write to:
|
||||||
|
# The Free Software Foundation, Inc.,
|
||||||
|
# 51 Franklin Street, Fifth Floor
|
||||||
|
# Boston, MA 02110-1301, USA.
|
||||||
|
#
|
||||||
|
|
||||||
|
from deluge.log import LOG as log
|
||||||
|
from deluge.plugins.pluginbase import CorePluginBase
|
||||||
|
import deluge.component as component
|
||||||
|
import deluge.configmanager
|
||||||
|
from deluge.core.rpcserver import export
|
||||||
|
|
||||||
|
class Core(CorePluginBase):
|
||||||
|
def enable(self):
|
||||||
|
log.debug("Example core plugin enabled!")
|
||||||
|
|
||||||
|
def disable(self):
|
||||||
|
log.debug("Example core plugin disabled!")
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
### Exported RPC methods ###
|
||||||
|
@export()
|
||||||
|
def example_method(self):
|
||||||
|
pass
|
|
@ -1,7 +1,7 @@
|
||||||
#
|
#
|
||||||
# core.py
|
# gtkui.py
|
||||||
#
|
#
|
||||||
# Copyright (C) 2007 Andrew Resch <andrewresch@gmail.com>
|
# Copyright (C) 2008 Andrew Resch <andrewresch@gmail.com>
|
||||||
#
|
#
|
||||||
# Deluge is free software.
|
# Deluge is free software.
|
||||||
#
|
#
|
||||||
|
@ -22,12 +22,16 @@
|
||||||
# Boston, MA 02110-1301, USA.
|
# Boston, MA 02110-1301, USA.
|
||||||
#
|
#
|
||||||
|
|
||||||
import deluge.component as component
|
import gtk
|
||||||
from deluge.log import LOG as log
|
|
||||||
|
|
||||||
class CorePluginBase:
|
from deluge.log import LOG as log
|
||||||
def __init__(self, plugin_api, plugin_name):
|
from deluge.ui.client import client
|
||||||
self.plugin = plugin_api
|
from deluge.plugins.pluginbase import GtkPluginBase
|
||||||
# Register RPC methods
|
import deluge.component as component
|
||||||
component.get("RPCServer").register_object(self, plugin_name.lower())
|
import deluge.common
|
||||||
log.debug("CorePlugin initialized..")
|
|
||||||
|
class GtkUI(GtkPluginBase):
|
||||||
|
def enable(self):
|
||||||
|
pass
|
||||||
|
def disable(self):
|
||||||
|
pass
|
|
@ -1,7 +1,7 @@
|
||||||
#
|
#
|
||||||
# coreclient.py
|
# webui.py
|
||||||
#
|
#
|
||||||
# Copyright (C) 2008 Martijn Voncken <mvoncken@gmail.com>
|
# Copyright (C) 2009 Martijn Voncken <mvoncken@gmail.com>
|
||||||
#
|
#
|
||||||
# Deluge is free software.
|
# Deluge is free software.
|
||||||
#
|
#
|
||||||
|
@ -23,19 +23,13 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
|
from deluge.log import LOG as log
|
||||||
|
from deluge.ui.client import client
|
||||||
|
from deluge import component
|
||||||
|
|
||||||
import deluge.component as component
|
class WebUI(WebPluginBase):
|
||||||
|
def enable(self):
|
||||||
class CoreClient(object):
|
log.debug("Example Web plugin enabled!")
|
||||||
"""
|
|
||||||
provides the uiclient interface to core plugins
|
|
||||||
see http://dev.deluge-torrent.org/wiki/Development/UiClient
|
|
||||||
"""
|
|
||||||
def __init__(self):
|
|
||||||
self.core = component.get("Core")
|
|
||||||
|
|
||||||
def __getattr__(self, func_name):
|
|
||||||
return self.core.funcs[func_name]
|
|
||||||
|
|
||||||
client = CoreClient()
|
|
||||||
|
|
||||||
|
def disable(self):
|
||||||
|
log.debug("Example Web plugin disabled!")
|
56
deluge/plugins/example/setup.py
Normal file
56
deluge/plugins/example/setup.py
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
#
|
||||||
|
# setup.py
|
||||||
|
#
|
||||||
|
# Copyright (C) 2008 Andrew Resch <andrewresch@gmail.com>
|
||||||
|
#
|
||||||
|
# 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 3, 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.
|
||||||
|
#
|
||||||
|
|
||||||
|
from setuptools import setup
|
||||||
|
|
||||||
|
__plugin_name__ = "Example"
|
||||||
|
__author__ = "Andrew Resch"
|
||||||
|
__author_email__ = "andrewresch@gmail.com"
|
||||||
|
__version__ = "1.2"
|
||||||
|
__url__ = "http://deluge-torrent.org"
|
||||||
|
__license__ = "GPLv3"
|
||||||
|
__description__ = "Example plugin"
|
||||||
|
__long_description__ = __description__
|
||||||
|
__pkg_data__ = {__plugin_name__.lower(): []}
|
||||||
|
|
||||||
|
setup(
|
||||||
|
name=__plugin_name__,
|
||||||
|
version=__version__,
|
||||||
|
description=__description__,
|
||||||
|
author=__author__,
|
||||||
|
author_email=__author_email__,
|
||||||
|
url=__url__,
|
||||||
|
license=__license__,
|
||||||
|
long_description=__long_description__,
|
||||||
|
|
||||||
|
packages=[__plugin_name__.lower()],
|
||||||
|
package_data = __pkg_data__,
|
||||||
|
|
||||||
|
entry_points="""
|
||||||
|
[deluge.plugin.core]
|
||||||
|
%s = %s:CorePlugin
|
||||||
|
[deluge.plugin.gtkui]
|
||||||
|
%s = %s:GtkUIPlugin
|
||||||
|
[deluge.plugin.webui]
|
||||||
|
%s = %s:WebUIPlugin
|
||||||
|
""" % ((__plugin_name__, __plugin_name__.lower())*3)
|
||||||
|
)
|
|
@ -22,36 +22,26 @@
|
||||||
# Boston, MA 02110-1301, USA.
|
# Boston, MA 02110-1301, USA.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
"""
|
||||||
|
This base class is used in plugin's __init__ for the plugin entry points.
|
||||||
|
"""
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
|
|
||||||
class PluginBase:
|
class PluginInitBase(object):
|
||||||
def __init__(self):
|
_plugin_cls = None
|
||||||
self.plugin = None
|
def __init__(self, plugin_name):
|
||||||
|
self.plugin = self._plugin_cls(plugin_name)
|
||||||
|
|
||||||
def enable(self):
|
def enable(self):
|
||||||
try:
|
try:
|
||||||
log.debug(0)
|
|
||||||
if hasattr(self.plugin, "base_enable"):
|
|
||||||
log.debug(1)
|
|
||||||
self.plugin.base_enable()
|
|
||||||
log.debug(2)
|
|
||||||
self.plugin.enable()
|
self.plugin.enable()
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
log.warning("Unable to enable plugin: %s", e)
|
log.error("Unable to enable plugin!")
|
||||||
else:
|
log.exception(e)
|
||||||
# If plugin was enabled, call it's update() right away
|
|
||||||
self.update()
|
|
||||||
|
|
||||||
def disable(self):
|
def disable(self):
|
||||||
try:
|
try:
|
||||||
if hasattr(self.plugin, "base_disable"):
|
|
||||||
self.plugin.base_disable()
|
|
||||||
self.plugin.disable()
|
self.plugin.disable()
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
log.warning("Unable to disable plugin: %s", e)
|
log.error("Unable to disable plugin!")
|
||||||
|
log.exception(e)
|
||||||
def update(self):
|
|
||||||
if hasattr(self.plugin, "update"):
|
|
||||||
self.plugin.update()
|
|
||||||
|
|
||||||
|
|
50
deluge/plugins/pluginbase.py
Normal file
50
deluge/plugins/pluginbase.py
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
#
|
||||||
|
# core.py
|
||||||
|
#
|
||||||
|
# Copyright (C) 2007 Andrew Resch <andrewresch@gmail.com>
|
||||||
|
#
|
||||||
|
# Deluge is free software.
|
||||||
|
#
|
||||||
|
# You may redistribute it and/or modify it under the terms of the
|
||||||
|
# GNU General Public License, as published by the Free Software
|
||||||
|
# Foundation; either version 3 of the License, or (at your option)
|
||||||
|
# any later version.
|
||||||
|
#
|
||||||
|
# deluge 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 deluge. If not, write to:
|
||||||
|
# The Free Software Foundation, Inc.,
|
||||||
|
# 51 Franklin Street, Fifth Floor
|
||||||
|
# Boston, MA 02110-1301, USA.
|
||||||
|
#
|
||||||
|
|
||||||
|
import deluge.component as component
|
||||||
|
from deluge.log import LOG as log
|
||||||
|
|
||||||
|
class PluginBase(component.Component):
|
||||||
|
def enable(self):
|
||||||
|
raise NotImplementedError("Need to define an enable method!")
|
||||||
|
|
||||||
|
def disable(self):
|
||||||
|
raise NotImplementedError("Need to define a disable method!")
|
||||||
|
|
||||||
|
class CorePluginBase(PluginBase):
|
||||||
|
def __init__(self, plugin_name):
|
||||||
|
component.Component.__init__(self, "CorePlugin." + plugin_name)
|
||||||
|
# Register RPC methods
|
||||||
|
component.get("RPCServer").register_object(self, plugin_name.lower())
|
||||||
|
log.debug("CorePlugin initialized..")
|
||||||
|
|
||||||
|
class GtkPluginBase(PluginBase):
|
||||||
|
def __init__(self, plugin_name):
|
||||||
|
component.Component.__init__(self, "GtkPlugin." + plugin_name)
|
||||||
|
log.debug("GtkPlugin initialized..")
|
||||||
|
|
||||||
|
class WebPluginBase(PluginBase):
|
||||||
|
def __init__(self, plugin_name):
|
||||||
|
component.Component.__init__(self, "WebPlugin." + plugin_name)
|
||||||
|
log.debug("WebPlugin initialized..")
|
Loading…
Add table
Add a link
Reference in a new issue