Add missing files.

Start of plugin support in gtkui.
This commit is contained in:
Andrew Resch 2007-08-11 06:46:41 +00:00
parent 13fc181fa2
commit 895f7e2761
10 changed files with 396 additions and 109 deletions

View File

@ -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

View File

@ -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):

View File

@ -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.

View File

@ -0,0 +1,46 @@
#
# torrentmanagerstate.py
#
# Copyright (C) 2007 Andrew Resch ('andar') <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 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 = []

View File

@ -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)

View File

@ -0,0 +1,146 @@
#
# core.py
#
# Copyright (C) 2007 Andrew Resch ('andar') <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 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")

View File

@ -0,0 +1,41 @@
#
# core.py
#
# Copyright (C) 2007 Andrew Resch ('andar') <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 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..")

View File

@ -0,0 +1,136 @@
#
# torrentqueue.py
#
# Copyright (C) 2007 Andrew Resch ('andar') <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 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

View File

@ -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
"""
)

View File

@ -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()