From 895f7e2761ad87c1bc618033b1029c188e6365ec Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Sat, 11 Aug 2007 06:46:41 +0000 Subject: [PATCH] Add missing files. Start of plugin support in gtkui. --- deluge/common.py | 4 + deluge/core/core.py | 3 +- deluge/core/pluginmanager.py | 5 +- deluge/core/torrentmanagerstate.py | 46 +++++++ deluge/plugins/queue/queue/__init__.py | 116 ++-------------- deluge/plugins/queue/queue/core.py | 146 +++++++++++++++++++++ deluge/plugins/queue/queue/gtkui.py | 41 ++++++ deluge/plugins/queue/queue/torrentqueue.py | 136 +++++++++++++++++++ deluge/plugins/queue/setup.py | 4 +- deluge/ui/gtkui/gtkui.py | 4 + 10 files changed, 396 insertions(+), 109 deletions(-) create mode 100644 deluge/core/torrentmanagerstate.py create mode 100644 deluge/plugins/queue/queue/core.py create mode 100644 deluge/plugins/queue/queue/gtkui.py create mode 100644 deluge/plugins/queue/queue/torrentqueue.py diff --git a/deluge/common.py b/deluge/common.py index 4daa2aeef..2d51b48ad 100644 --- a/deluge/common.py +++ b/deluge/common.py @@ -62,6 +62,10 @@ def get_default_download_dir(): def get_default_torrent_dir(): """Returns the default torrent directory""" return os.path.join(get_config_dir(), "torrentfiles") + +def get_default_plugin_dir(): + """Returns the default plugin directory""" + return os.path.join(get_config_dir(), "plugins") ## Formatting text functions diff --git a/deluge/core/core.py b/deluge/core/core.py index e8922fa79..bb84e7081 100644 --- a/deluge/core/core.py +++ b/deluge/core/core.py @@ -64,7 +64,8 @@ DEFAULT_PREFS = { "compact_allocation": True, "download_location": deluge.common.get_default_download_dir(), "listen_ports": [6881, 6891], - "torrentfiles_location": deluge.common.get_default_torrent_dir() + "torrentfiles_location": deluge.common.get_default_torrent_dir(), + "plugins_location": deluge.common.get_default_plugin_dir() } class Core(dbus.service.Object): diff --git a/deluge/core/pluginmanager.py b/deluge/core/pluginmanager.py index d3885b53d..21bc5d114 100644 --- a/deluge/core/pluginmanager.py +++ b/deluge/core/pluginmanager.py @@ -42,7 +42,10 @@ log = logging.getLogger("deluge") class PluginManager: def __init__(self): # Set up the hooks dictionary - self.hooks = {"post_torrent_add": []} + self.hooks = { + "post_torrent_add": [], + "post_torrent_remove": [] + } # This will load any .eggs in the plugins folder inside the main # deluge egg.. Need to scan the local plugin folder too. diff --git a/deluge/core/torrentmanagerstate.py b/deluge/core/torrentmanagerstate.py new file mode 100644 index 000000000..55c3d96ce --- /dev/null +++ b/deluge/core/torrentmanagerstate.py @@ -0,0 +1,46 @@ +# +# torrentmanagerstate.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. + +import logging + +# Get the logger +log = logging.getLogger("deluge") + +class TorrentState: + def __init__(self, torrent_id, filename): + self.torrent_id = torrent_id + self.filename = filename + +class TorrentManagerState: + def __init__(self): + self.torrents = [] diff --git a/deluge/plugins/queue/queue/__init__.py b/deluge/plugins/queue/queue/__init__.py index 0c219b53f..d5e50baad 100644 --- a/deluge/plugins/queue/queue/__init__.py +++ b/deluge/plugins/queue/queue/__init__.py @@ -33,114 +33,18 @@ import logging -try: - import dbus, dbus.service - dbus_version = getattr(dbus, "version", (0,0,0)) - if dbus_version >= (0,41,0) and dbus_version < (0,80,0): - import dbus.glib - elif dbus_version >= (0,80,0): - from dbus.mainloop.glib import DBusGMainLoop - DBusGMainLoop(set_as_default=True) - else: - pass -except: dbus_imported = False -else: dbus_imported = True - -from torrentqueue import TorrentQueue +from core import Core +from gtkui import GtkUI # Get the logger log = logging.getLogger("deluge") -class QueueCorePlugin(dbus.service.Object): - def __init__(self, plugin, path="/org/deluge_torrent/Plugin/Queue"): - # Get the pluginmanager reference - self.plugin = plugin +class CorePlugin: + def __init__(self, plugin_manager): + # Load the Core portion of the plugin + self.core = Core(plugin_manager) - # Setup DBUS - bus_name = dbus.service.BusName("org.deluge_torrent.Deluge", - bus=dbus.SessionBus()) - - dbus.service.Object.__init__(self, bus_name, path) - - # Instantiate the TorrentQueue object - self.queue = TorrentQueue() - - # Register core hooks - self.plugin.register_hook("post_torrent_add", self.post_torrent_add) - self.plugin.register_hook("post_torrent_remove", - self.post_torrent_remove) - - log.info("Queue plugin initialized..") - - ## Hooks for core ## - def post_torrent_add(self, torrent_id): - if torrent_id is not None: - self.queue.append(torrent_id) - - def post_torrent_remove(self, torrent_id): - if torrent_id is not None: - self.queue.remove(torrent_id) - - ## Queueing functions ## - @dbus.service.method(dbus_interface="org.deluge_torrent.Deluge.Queue", - in_signature="s", out_signature="") - def queue_top(self, torrent_id): - log.debug("Attempting to queue %s to top", torrent_id) - try: - # If the queue method returns True, then we should emit a signal - if self.queue.top(torrent_id): - self.torrent_queue_changed() - except KeyError: - log.warning("torrent_id: %s does not exist in the queue", - torrent_id) - - @dbus.service.method(dbus_interface="org.deluge_torrent.Deluge.Queue", - in_signature="s", out_signature="") - def queue_up(self, torrent_id): - log.debug("Attempting to queue %s to up", torrent_id) - try: - # If the queue method returns True, then we should emit a signal - if self.queue.up(torrent_id): - self.torrent_queue_changed() - except KeyError: - log.warning("torrent_id: %s does not exist in the queue", - torrent_id) - - @dbus.service.method(dbus_interface="org.deluge_torrent.Deluge.Queue", - in_signature="s", out_signature="") - def queue_down(self, torrent_id): - log.debug("Attempting to queue %s to down", torrent_id) - try: - # If the queue method returns True, then we should emit a signal - if self.queue.down(torrent_id): - self.torrent_queue_changed() - except KeyError: - log.warning("torrent_id: %s does not exist in the queue", - torrent_id) - - @dbus.service.method(dbus_interface="org.deluge_torrent.Deluge.Queue", - in_signature="s", out_signature="") - def queue_bottom(self, torrent_id): - log.debug("Attempting to queue %s to bottom", torrent_id) - try: - # If the queue method returns True, then we should emit a signal - if self.queue.bottom(torrent_id): - self.torrent_queue_changed() - except KeyError: - log.warning("torrent_id: %s does not exist in the queue", - torrent_id) - - @dbus.service.method(dbus_interface="org.deluge_torrent.Deluge.Queue", - in_signature="", out_signature="as") - def get_queue(self): - """Returns the queue list. - """ - log.debug("Getting queue list") - return self.queue.queue - - ## Signals ## - @dbus.service.signal(dbus_interface="org.deluge_torrent.Deluge.Queue", - signature="") - def torrent_queue_changed(self): - """Emitted when a torrent queue position is changed""" - log.debug("torrent_queue_changed signal emitted") +class GtkUIPlugin: + def __init__(self, plugin_manager): + # Load the GtkUI portion of the plugin + self.gtkui = GtkUI(plugin_manager) diff --git a/deluge/plugins/queue/queue/core.py b/deluge/plugins/queue/queue/core.py new file mode 100644 index 000000000..09936e1f1 --- /dev/null +++ b/deluge/plugins/queue/queue/core.py @@ -0,0 +1,146 @@ +# +# 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. + +import logging + +try: + import dbus, dbus.service + dbus_version = getattr(dbus, "version", (0,0,0)) + if dbus_version >= (0,41,0) and dbus_version < (0,80,0): + import dbus.glib + elif dbus_version >= (0,80,0): + from dbus.mainloop.glib import DBusGMainLoop + DBusGMainLoop(set_as_default=True) + else: + pass +except: dbus_imported = False +else: dbus_imported = True + +from torrentqueue import TorrentQueue + +# Get the logger +log = logging.getLogger("deluge") + +class Core(dbus.service.Object): + def __init__(self, plugin, path="/org/deluge_torrent/Plugin/Queue"): + # Get the pluginmanager reference + self.plugin = plugin + + # Setup DBUS + bus_name = dbus.service.BusName("org.deluge_torrent.Deluge", + bus=dbus.SessionBus()) + + dbus.service.Object.__init__(self, bus_name, path) + + # Instantiate the TorrentQueue object + self.queue = TorrentQueue() + + # Register core hooks + self.plugin.register_hook("post_torrent_add", self.post_torrent_add) + self.plugin.register_hook("post_torrent_remove", + self.post_torrent_remove) + + log.info("Queue Core plugin initialized..") + + ## Hooks for core ## + def post_torrent_add(self, torrent_id): + if torrent_id is not None: + self.queue.append(torrent_id) + + def post_torrent_remove(self, torrent_id): + if torrent_id is not None: + self.queue.remove(torrent_id) + + ## Queueing functions ## + @dbus.service.method(dbus_interface="org.deluge_torrent.Deluge.Queue", + in_signature="s", out_signature="") + def queue_top(self, torrent_id): + log.debug("Attempting to queue %s to top", torrent_id) + try: + # If the queue method returns True, then we should emit a signal + if self.queue.top(torrent_id): + self.torrent_queue_changed() + except KeyError: + log.warning("torrent_id: %s does not exist in the queue", + torrent_id) + + @dbus.service.method(dbus_interface="org.deluge_torrent.Deluge.Queue", + in_signature="s", out_signature="") + def queue_up(self, torrent_id): + log.debug("Attempting to queue %s to up", torrent_id) + try: + # If the queue method returns True, then we should emit a signal + if self.queue.up(torrent_id): + self.torrent_queue_changed() + except KeyError: + log.warning("torrent_id: %s does not exist in the queue", + torrent_id) + + @dbus.service.method(dbus_interface="org.deluge_torrent.Deluge.Queue", + in_signature="s", out_signature="") + def queue_down(self, torrent_id): + log.debug("Attempting to queue %s to down", torrent_id) + try: + # If the queue method returns True, then we should emit a signal + if self.queue.down(torrent_id): + self.torrent_queue_changed() + except KeyError: + log.warning("torrent_id: %s does not exist in the queue", + torrent_id) + + @dbus.service.method(dbus_interface="org.deluge_torrent.Deluge.Queue", + in_signature="s", out_signature="") + def queue_bottom(self, torrent_id): + log.debug("Attempting to queue %s to bottom", torrent_id) + try: + # If the queue method returns True, then we should emit a signal + if self.queue.bottom(torrent_id): + self.torrent_queue_changed() + except KeyError: + log.warning("torrent_id: %s does not exist in the queue", + torrent_id) + + @dbus.service.method(dbus_interface="org.deluge_torrent.Deluge.Queue", + in_signature="", out_signature="as") + def get_queue(self): + """Returns the queue list. + """ + log.debug("Getting queue list") + return self.queue.queue + + ## Signals ## + @dbus.service.signal(dbus_interface="org.deluge_torrent.Deluge.Queue", + signature="") + def torrent_queue_changed(self): + """Emitted when a torrent queue position is changed""" + log.debug("torrent_queue_changed signal emitted") diff --git a/deluge/plugins/queue/queue/gtkui.py b/deluge/plugins/queue/queue/gtkui.py new file mode 100644 index 000000000..be44a0ac4 --- /dev/null +++ b/deluge/plugins/queue/queue/gtkui.py @@ -0,0 +1,41 @@ +# +# 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. + +import logging + +# Get the logger +log = logging.getLogger("deluge") + +class GtkUI: + def __init__(self, plugin_manager): + log.debug("Queue GtkUI plugin initalized..") diff --git a/deluge/plugins/queue/queue/torrentqueue.py b/deluge/plugins/queue/queue/torrentqueue.py new file mode 100644 index 000000000..5ce3a2ed8 --- /dev/null +++ b/deluge/plugins/queue/queue/torrentqueue.py @@ -0,0 +1,136 @@ +# +# torrentqueue.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. + +import logging + +# Get the logger +log = logging.getLogger("deluge") + +class TorrentQueue: + def __init__(self): + self.queue = [] + + def __getitem__(self, torrent_id): + """Return the queue position of the torrent_id""" + return self.queue.index(torrent_id) + + def append(self, torrent_id): + """Append torrent_id to the bottom of the queue""" + log.debug("Append torrent %s to queue..", torrent_id) + self.queue.append(torrent_id) + + def prepend(self, torrent_id): + """Prepend torrent_id to the top of the queue""" + log.debug("Prepend torrent %s to queue..", torrent_id) + self.queue.insert(0, torrent_id) + + def remove(self, torrent_id): + """Removes torrent_id from the list""" + log.debug("Remove torrent %s from queue..", torrent_id) + self.queue.remove(torrent_id) + + def up(self, torrent_id): + """Move torrent_id up one in the queue""" + if torrent_id not in self.queue: + # Raise KeyError if the torrent_id is not in the queue + raise KeyError + + log.debug("Move torrent %s up..", torrent_id) + # Get the index of the torrent_id + index = self.queue.index(torrent_id) + + # Can't queue up if torrent is already at top + if index is 0: + return False + + # Pop and insert the torrent_id at index - 1 + self.queue.insert(index - 1, self.queue.pop(index)) + + return True + + def top(self, torrent_id): + """Move torrent_id to top of the queue""" + if torrent_id not in self.queue: + # Raise KeyError if the torrent_id is not in the queue + raise KeyError + + log.debug("Move torrent %s to top..", torrent_id) + # Get the index of the torrent_id + index = self.queue.index(torrent_id) + + # Can't queue up if torrent is already at top + if index is 0: + return False + + # Pop and prepend the torrent_id + self.prepend(self.queue.pop(index)) + + return True + + def down(self, torrent_id): + """Move torrent_id down one in the queue""" + if torrent_id not in self.queue: + # Raise KeyError if torrent_id is not in the queue + raise KeyError + + log.debug("Move torrent %s down..", torrent_id) + # Get the index of the torrent_id + index = self.queue.index(torrent_id) + + # Can't queue down of torrent_id is at bottom + if index is len(self.queue) - 1: + return False + + # Pop and insert the torrent_id at index + 1 + self.queue.insert(index + 1, self.queue.pop(index)) + + return True + + def bottom(self, torrent_id): + """Move torrent_id to bottom of the queue""" + if torrent_id not in self.queue: + # Raise KeyError if torrent_id is not in the queue + raise KeyError + + log.debug("Move torrent %s to bottom..", torrent_id) + # Get the index of the torrent_id + index = self.queue.index(torrent_id) + + # Can't queue down of torrent_id is at bottom + if index is len(self.queue) - 1: + return False + + # Pop and append the torrent_id + self.append(self.queue.pop(index)) + + return True diff --git a/deluge/plugins/queue/setup.py b/deluge/plugins/queue/setup.py index 77f9669b9..fe58e2380 100644 --- a/deluge/plugins/queue/setup.py +++ b/deluge/plugins/queue/setup.py @@ -44,6 +44,8 @@ setup( packages=["queue"], entry_points=""" [deluge.plugin.core] - Queue = queue:QueueCorePlugin + Queue = queue:CorePlugin + [deluge.plugin.ui.gtk] + Queue = queue:GtkUIPlugin """ ) diff --git a/deluge/ui/gtkui/gtkui.py b/deluge/ui/gtkui/gtkui.py index ee1f34e4e..2a4e83635 100644 --- a/deluge/ui/gtkui/gtkui.py +++ b/deluge/ui/gtkui/gtkui.py @@ -41,6 +41,7 @@ import pkg_resources from mainwindow import MainWindow from signals import Signals +from pluginmanager import PluginManager # Get the logger log = logging.getLogger("deluge") @@ -64,6 +65,9 @@ class GtkUI: # Start the signal receiver self.signal_receiver = Signals(self) + # Initalize the plugins + self.plugins = PluginManager() + # Show the main window self.main_window.show()