diff --git a/deluge/pluginmanagerbase.py b/deluge/pluginmanagerbase.py index 0817281e2..0ae7c45e3 100644 --- a/deluge/pluginmanagerbase.py +++ b/deluge/pluginmanagerbase.py @@ -115,7 +115,11 @@ class PluginManagerBase: for name in egg.get_entry_map(self.entry_name): entry_point = egg.get_entry_info(self.entry_name, name) 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() plugin_name = plugin_name.replace("-", " ") self.plugins[plugin_name] = instance diff --git a/deluge/plugins/blocklist/blocklist/__init__.py b/deluge/plugins/blocklist/blocklist/__init__.py index fe2b54edf..c385b25b2 100644 --- a/deluge/plugins/blocklist/blocklist/__init__.py +++ b/deluge/plugins/blocklist/blocklist/__init__.py @@ -24,35 +24,36 @@ # Boston, MA 02110-1301, USA. # - from deluge.log import LOG as log -from deluge.plugins.init import PluginBase +from deluge.plugins.init import PluginInitBase -class CorePlugin(PluginBase): - def __init__(self, plugin_api, plugin_name): +class CorePlugin(PluginInitBase): + def __init__(self, plugin_name): # Load the Core portion of the plugin try: from core import Core - self.plugin = Core(plugin_api, plugin_name) + self.plugin = Core(plugin_name) 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): - def __init__(self, plugin_api, plugin_name): +class GtkUIPlugin(PluginInitBase): + def __init__(self, plugin_name): # Load the GtkUI portion of the plugin try: from gtkui import GtkUI - self.plugin = GtkUI(plugin_api, plugin_name) + self.plugin = GtkUI(plugin_name) 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): - def __init__(self, plugin_api, plugin_name): - # Load the GtkUI portion of the plugin +class WebUIPlugin(PluginInitBase): + def __init__(self, plugin_name): + # Load the WebUI portion of the plugin try: from webui import WebUI - self.plugin = WebUI(plugin_api, plugin_name) + self.plugin = WebUI(plugin_name) 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) diff --git a/deluge/plugins/example/example/__init__.py b/deluge/plugins/example/example/__init__.py new file mode 100644 index 000000000..ba3508a45 --- /dev/null +++ b/deluge/plugins/example/example/__init__.py @@ -0,0 +1,35 @@ +# +# __init__.py +# +# Copyright (C) 2009 Andrew Resch +# +# 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 diff --git a/deluge/plugins/example/example/common.py b/deluge/plugins/example/example/common.py new file mode 100644 index 000000000..01a6b7c44 --- /dev/null +++ b/deluge/plugins/example/example/common.py @@ -0,0 +1,29 @@ +# +# common.py +# +# Copyright (C) 2009 Andrew Resch +# +# 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)) diff --git a/deluge/plugins/example/example/core.py b/deluge/plugins/example/example/core.py new file mode 100644 index 000000000..6361c7c84 --- /dev/null +++ b/deluge/plugins/example/example/core.py @@ -0,0 +1,44 @@ +# +# core.py +# +# Copyright (C) 2009 Andrew Resch +# +# 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 diff --git a/deluge/plugins/corepluginbase.py b/deluge/plugins/example/example/gtkui.py similarity index 70% rename from deluge/plugins/corepluginbase.py rename to deluge/plugins/example/example/gtkui.py index a2ac6aa26..92e5baaa6 100644 --- a/deluge/plugins/corepluginbase.py +++ b/deluge/plugins/example/example/gtkui.py @@ -1,7 +1,7 @@ # -# core.py +# gtkui.py # -# Copyright (C) 2007 Andrew Resch +# Copyright (C) 2008 Andrew Resch # # Deluge is free software. # @@ -22,12 +22,16 @@ # Boston, MA 02110-1301, USA. # -import deluge.component as component -from deluge.log import LOG as log +import gtk -class CorePluginBase: - def __init__(self, plugin_api, plugin_name): - self.plugin = plugin_api - # Register RPC methods - component.get("RPCServer").register_object(self, plugin_name.lower()) - log.debug("CorePlugin initialized..") +from deluge.log import LOG as log +from deluge.ui.client import client +from deluge.plugins.pluginbase import GtkPluginBase +import deluge.component as component +import deluge.common + +class GtkUI(GtkPluginBase): + def enable(self): + pass + def disable(self): + pass diff --git a/deluge/plugins/coreclient.py b/deluge/plugins/example/example/webui.py similarity index 61% rename from deluge/plugins/coreclient.py rename to deluge/plugins/example/example/webui.py index d39778098..c75ce8858 100644 --- a/deluge/plugins/coreclient.py +++ b/deluge/plugins/example/example/webui.py @@ -1,7 +1,7 @@ # -# coreclient.py +# webui.py # -# Copyright (C) 2008 Martijn Voncken +# Copyright (C) 2009 Martijn Voncken # # 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 CoreClient(object): - """ - 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() +class WebUI(WebPluginBase): + def enable(self): + log.debug("Example Web plugin enabled!") + def disable(self): + log.debug("Example Web plugin disabled!") diff --git a/deluge/plugins/example/setup.py b/deluge/plugins/example/setup.py new file mode 100644 index 000000000..12042d54a --- /dev/null +++ b/deluge/plugins/example/setup.py @@ -0,0 +1,56 @@ +# +# setup.py +# +# Copyright (C) 2008 Andrew Resch +# +# 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) +) diff --git a/deluge/plugins/init.py b/deluge/plugins/init.py index 533a33f84..08f4f53b5 100644 --- a/deluge/plugins/init.py +++ b/deluge/plugins/init.py @@ -22,36 +22,26 @@ # 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 -class PluginBase: - def __init__(self): - self.plugin = None +class PluginInitBase(object): + _plugin_cls = None + def __init__(self, plugin_name): + self.plugin = self._plugin_cls(plugin_name) def enable(self): try: - log.debug(0) - if hasattr(self.plugin, "base_enable"): - log.debug(1) - self.plugin.base_enable() - log.debug(2) self.plugin.enable() except Exception, e: - log.warning("Unable to enable plugin: %s", e) - else: - # If plugin was enabled, call it's update() right away - self.update() + log.error("Unable to enable plugin!") + log.exception(e) def disable(self): try: - if hasattr(self.plugin, "base_disable"): - self.plugin.base_disable() self.plugin.disable() except Exception, e: - log.warning("Unable to disable plugin: %s", e) - - def update(self): - if hasattr(self.plugin, "update"): - self.plugin.update() - + log.error("Unable to disable plugin!") + log.exception(e) diff --git a/deluge/plugins/pluginbase.py b/deluge/plugins/pluginbase.py new file mode 100644 index 000000000..445b515de --- /dev/null +++ b/deluge/plugins/pluginbase.py @@ -0,0 +1,50 @@ +# +# core.py +# +# Copyright (C) 2007 Andrew Resch +# +# 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..")