diff --git a/deluge/core/core.py b/deluge/core/core.py index 18283052f..449d6c3f4 100644 --- a/deluge/core/core.py +++ b/deluge/core/core.py @@ -375,9 +375,11 @@ class Core( def export_enable_plugin(self, plugin): self.plugins.enable_plugin(plugin) - + return None + def export_disable_plugin(self, plugin): self.plugins.disable_plugin(plugin) + return None # Signals def torrent_added(self, torrent_id): diff --git a/deluge/pluginmanagerbase.py b/deluge/pluginmanagerbase.py index ae41be976..dadfb1759 100644 --- a/deluge/pluginmanagerbase.py +++ b/deluge/pluginmanagerbase.py @@ -90,34 +90,38 @@ class PluginManagerBase: self.available_plugins = [] for name in self.pkg_env: - pkg_name = str(self.pkg_env[name][0]).split()[0] + pkg_name = str(self.pkg_env[name][0]).split()[0].replace("-", " ") pkg_version = str(self.pkg_env[name][0]).split()[1] - log.debug("Found plugin: %s %s", pkg_name, pkg_version) self.available_plugins.append(pkg_name) - def enable_plugin(self, name): + def enable_plugin(self, plugin_name): """Enables a plugin""" - if name not in self.available_plugins: + if plugin_name not in self.available_plugins: log.warning("Cannot enable non-existant plugin %s", name) return - - egg = self.pkg_env[name][0] + + plugin_name = plugin_name.replace(" ", "-") + egg = self.pkg_env[plugin_name][0] egg.activate() 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) - self.plugins[name] = instance - log.info("Plugin %s enabled..", name) + plugin_name = plugin_name.replace("-", " ") + self.plugins[plugin_name] = instance + if plugin_name not in self.config["enabled_plugins"]: + self.config["enabled_plugins"].append(plugin_name) + log.info("Plugin %s enabled..", plugin_name) def disable_plugin(self, name): """Disables a plugin""" self.plugins[name].disable() - - del self.plugins[name] -# except: - # log.warning("Unable to disable non-existant plugin %s", name) - + try: + del self.plugins[name] + self.config["enabled_plugins"].remove(plugin_name) + except KeyError: + log.warning("Plugin %s is not enabled..", name) + log.info("Plugin %s disabled..", name) diff --git a/deluge/plugins/__init__.py b/deluge/plugins/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/deluge/plugins/init.py b/deluge/plugins/init.py new file mode 100644 index 000000000..5891c4616 --- /dev/null +++ b/deluge/plugins/init.py @@ -0,0 +1,9 @@ +class PluginBase: + def __init__(self): + pass + + def enable(self): + pass + def disable(self): + pass + diff --git a/deluge/plugins/testp/setup.py b/deluge/plugins/testp/setup.py new file mode 100644 index 000000000..2d972c15d --- /dev/null +++ b/deluge/plugins/testp/setup.py @@ -0,0 +1,52 @@ +# setup.py +# +# Copyright (C) 2007 Andrew Resch ('andar') +# +# 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. +# +# In addition, as a special exception, the copyright holders give +# permission to link the code of portions of this program with the OpenSSL +# library. +# You must obey the GNU General Public License in all respects for all of +# the code used other than OpenSSL. If you modify file(s) with this +# exception, you may extend this exception to your version of the file(s), +# but you are not obligated to do so. If you do not wish to do so, delete +# this exception statement from your version. If you delete this exception +# statement from all source files in the program, then also delete it here. + +""" +Test plugin +""" + +from setuptools import setup + +__author__ = "Andrew Resch" + +setup( + name="Test Plugin", + version="1.0", + description=__doc__, + author=__author__, + packages=["testp"], + package_data = {"testp": ["glade/*.glade"]}, + entry_points=""" + [deluge.plugin.core] + Testp = testp:CorePlugin + [deluge.plugin.gtkui] + Testp = testp:GtkUIPlugin + """ +) diff --git a/deluge/plugins/testp/testp/__init__.py b/deluge/plugins/testp/testp/__init__.py new file mode 100644 index 000000000..19ace0e75 --- /dev/null +++ b/deluge/plugins/testp/testp/__init__.py @@ -0,0 +1,54 @@ +# +# __init__.py +# +# Copyright (C) 2007 Andrew Resch ('andar') +# +# 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 2 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. +# +# In addition, as a special exception, the copyright holders give +# permission to link the code of portions of this program with the OpenSSL +# library. +# You must obey the GNU General Public License in all respects for all of +# the code used other than OpenSSL. If you modify file(s) with this +# exception, you may extend this exception to your version of the file(s), +# but you are not obligated to do so. If you do not wish to do so, delete +# this exception statement from your version. If you delete this exception +# statement from all source files in the program, then also delete it here. + +from deluge.log import LOG as log + +from deluge.plugins.init import PluginBase + +class CorePlugin(PluginBase): + def __init__(self, plugin_manager): + # Load the Core portion of the plugin + try: + from core import Core + self.core = Core() + except: + pass + +class GtkUIPlugin(PluginBase): + def __init__(self, plugin_manager): + # Load the GtkUI portion of the plugin + try: + from gtkui import GtkUI + self.gtkui = GtkUI() + except: + pass diff --git a/deluge/plugins/testp/testp/core.py b/deluge/plugins/testp/testp/core.py new file mode 100644 index 000000000..2f6fb4bc8 --- /dev/null +++ b/deluge/plugins/testp/testp/core.py @@ -0,0 +1,44 @@ +# +# core.py +# +# Copyright (C) 2007 Andrew Resch ('andar') +# +# 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 2 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. +# +# In addition, as a special exception, the copyright holders give +# permission to link the code of portions of this program with the OpenSSL +# library. +# You must obey the GNU General Public License in all respects for all of +# the code used other than OpenSSL. If you modify file(s) with this +# exception, you may extend this exception to your version of the file(s), +# but you are not obligated to do so. If you do not wish to do so, delete +# this exception statement from your version. If you delete this exception +# statement from all source files in the program, then also delete it here. + +from deluge.log import LOG as log + +class Core: + def __init__(self): + pass + + def enable(self): + pass + + def disable(self): + pass diff --git a/deluge/plugins/testp/testp/gtkui.py b/deluge/plugins/testp/testp/gtkui.py new file mode 100644 index 000000000..9beb6e76d --- /dev/null +++ b/deluge/plugins/testp/testp/gtkui.py @@ -0,0 +1,43 @@ +# +# gtkui.py +# +# Copyright (C) 2007 Andrew Resch ('andar') +# +# 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 2 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. +# +# In addition, as a special exception, the copyright holders give +# permission to link the code of portions of this program with the OpenSSL +# library. +# You must obey the GNU General Public License in all respects for all of +# the code used other than OpenSSL. If you modify file(s) with this +# exception, you may extend this exception to your version of the file(s), +# but you are not obligated to do so. If you do not wish to do so, delete +# this exception statement from your version. If you delete this exception +# statement from all source files in the program, then also delete it here. + +from deluge.log import LOG as log +import ui + +class GtkUI(ui.UI): + def __init__(self): + ui.UI.__init__(self) + log.debug("gtkui plugin initialized..") + + + diff --git a/deluge/plugins/testp/testp/ui.py b/deluge/plugins/testp/testp/ui.py new file mode 100644 index 000000000..babd15a3e --- /dev/null +++ b/deluge/plugins/testp/testp/ui.py @@ -0,0 +1,44 @@ +# +# ui.py +# +# Copyright (C) 2007 Andrew Resch ('andar') +# +# 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 2 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. +# +# In addition, as a special exception, the copyright holders give +# permission to link the code of portions of this program with the OpenSSL +# library. +# You must obey the GNU General Public License in all respects for all of +# the code used other than OpenSSL. If you modify file(s) with this +# exception, you may extend this exception to your version of the file(s), +# but you are not obligated to do so. If you do not wish to do so, delete +# this exception statement from your version. If you delete this exception +# statement from all source files in the program, then also delete it here. + +from deluge.log import LOG as log + +class UI: + def __init__(self): + pass + + def enable(self): + pass + + def disable(self): + pass diff --git a/deluge/ui/client.py b/deluge/ui/client.py index 703a3f0e1..6578684ee 100644 --- a/deluge/ui/client.py +++ b/deluge/ui/client.py @@ -217,6 +217,10 @@ def get_torrent_status(torrent_id, keys): except (AttributeError, socket.error): set_core_uri(None) return {} + + if status == None: + return {} + return pickle.loads(status.data) def get_session_state(): @@ -301,17 +305,15 @@ def get_num_connections(): def enable_plugin(plugin): try: - return get_core().enable_plugin(plugin) + get_core().enable_plugin(plugin) except (AttributeError, socket.error): set_core_uri(None) - return def disable_plugin(plugin): try: - return get_core().disable_plugin(plugin) + get_core().disable_plugin(plugin) except (AttributeError, socket.error): set_core_uri(None) - return def open_url_in_browser(url): """Opens link in the desktop's default browser""" diff --git a/deluge/ui/gtkui/gtkui.py b/deluge/ui/gtkui/gtkui.py index bf44caf06..9a5b0ce27 100644 --- a/deluge/ui/gtkui/gtkui.py +++ b/deluge/ui/gtkui/gtkui.py @@ -121,7 +121,7 @@ class GtkUI: self.signal_receiver = Signals() # Initalize the plugins - self.plugins = PluginManager(self) + self.plugins = PluginManager() # Show the connection manager self.connectionmanager = ConnectionManager() diff --git a/deluge/ui/gtkui/pluginmanager.py b/deluge/ui/gtkui/pluginmanager.py index 3d9bbfd12..b5084226a 100644 --- a/deluge/ui/gtkui/pluginmanager.py +++ b/deluge/ui/gtkui/pluginmanager.py @@ -37,17 +37,11 @@ import deluge.ui.client as client from deluge.configmanager import ConfigManager from deluge.log import LOG as log -class PluginManager(deluge.pluginmanagerbase.PluginManagerBase): - def __init__(self, gtkui): - +class PluginManager(deluge.pluginmanagerbase.PluginManagerBase, + component.Component): + def __init__(self): + component.Component.__init__(self, "PluginManager") self.config = ConfigManager("gtkui.conf") - self._gtkui = gtkui - - # Register a callback with the client - client.connect_on_new_core(self.start) - - deluge.pluginmanagerbase.PluginManagerBase.__init__( - self, "gtkui.conf", "deluge.plugin.gtkui") def start(self): """Start the plugin manager""" @@ -58,29 +52,24 @@ class PluginManager(deluge.pluginmanagerbase.PluginManagerBase): self.config["enabled_plugins"] = enabled_plugins deluge.pluginmanagerbase.PluginManagerBase.__init__( - self, "gtkui.conf", "deluge.plugin.ui.gtk") + self, "gtkui.conf", "deluge.plugin.gtkui") def get_torrentview(self): """Returns a reference to the torrentview component""" - #return self._gtkui.mainwindow.torrentview return component.get("TorrentView") def get_toolbar(self): """Returns a reference to the toolbar component""" -# return self._gtkui.mainwindow.toolbar return component.get("ToolBar") def get_menubar(self): """Returns a reference to the menubar component""" - # return self._gtkui.mainwindow.menubar return component.get("MenuBar") def get_torrentmenu(self): """Returns a reference to the torrentmenu component""" -# return self._gtkui.mainwindow.menubar.torrentmenu return component.get("MenuBar").torrentmenu def get_selected_torrents(self): """Returns a list of the selected torrent_ids""" -# return self._gtkui.mainwindow.torrentview.get_selected_torrents() return component.get("TorrentView").get_selected_torrents() diff --git a/deluge/ui/gtkui/preferences.py b/deluge/ui/gtkui/preferences.py index 4acb1a0d1..52d098503 100644 --- a/deluge/ui/gtkui/preferences.py +++ b/deluge/ui/gtkui/preferences.py @@ -438,8 +438,10 @@ class Preferences(component.Component): self.plugin_liststore.set_value(row, 1, not value) if not value: client.enable_plugin(name) + component.get("PluginManager").enable_plugin(name) else: client.disable_plugin(name) + component.get("PluginManager").disable_plugin(name) def on_plugin_selection_changed(self, treeselection): log.debug("on_plugin_selection_changed")