From b187d02c9411266dfbeb49336279b53eab4cc420 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Mon, 3 Sep 2007 06:35:31 +0000 Subject: [PATCH] Change torrent_add_file() method in core to return a boolean value based on the success of the torrent add. Removed the torrent_add_failed() signal from core. --- deluge/core/core.py | 12 ++++-------- deluge/ui/functions.py | 14 ++++---------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/deluge/core/core.py b/deluge/core/core.py index 73271f7bb..755c3e58f 100644 --- a/deluge/core/core.py +++ b/deluge/core/core.py @@ -96,7 +96,7 @@ class Core(dbus.service.Object): del self.session @dbus.service.method(dbus_interface="org.deluge_torrent.Deluge", - in_signature="say", out_signature="") + in_signature="say", out_signature="b") def add_torrent_file(self, filename, filedump): """Adds a torrent file to the libtorrent session This requires the torrents filename and a dump of it's content @@ -109,8 +109,10 @@ class Core(dbus.service.Object): if torrent_id is not None: # Emit the torrent_added signal self.torrent_added(torrent_id) + return True else: - self.torrent_add_failed() + # Return False because the torrent was not added successfully + return False @dbus.service.method(dbus_interface="org.deluge_torrent.Deluge", in_signature="s", out_signature="") @@ -177,12 +179,6 @@ class Core(dbus.service.Object): """Emitted when a new torrent is added to the core""" log.debug("torrent_added signal emitted") - @dbus.service.signal(dbus_interface="org.deluge_torrent.Deluge", - signature="") - def torrent_add_failed(self): - """Emitted when a new torrent fails addition to the session""" - log.debug("torrent_add_failed signal emitted") - @dbus.service.signal(dbus_interface="org.deluge_torrent.Deluge", signature="s") def torrent_removed(self, torrent_id): diff --git a/deluge/ui/functions.py b/deluge/ui/functions.py index c40e84a06..505000ece 100644 --- a/deluge/ui/functions.py +++ b/deluge/ui/functions.py @@ -85,8 +85,11 @@ def add_torrent_file(torrent_files): f = open(torrent_file, "rb") # Get the filename because the core doesn't want a path. (path, filename) = os.path.split(torrent_file) - core.add_torrent_file(filename, f.read()) + result = core.add_torrent_file(filename, f.read()) f.close() + if result is False: + # The torrent was not added successfully. + log.warning("Torrent %s was not added successfully.", filename) def remove_torrent(torrent_ids): """Removes torrent_ids from the core.. Expects a list of torrent_ids""" @@ -107,15 +110,6 @@ def resume_torrent(torrent_ids): for torrent_id in torrent_ids: core.resume_torrent(torrent_id) -def get_torrent_info(core, torrent_id): - """Builds the info dictionary and returns it""" - info = core.get_torrent_info(torrent_id) - # Join the array of bytes into a string for pickle to read - info = "".join(chr(b) for b in info) - # De-serialize the object - info = pickle.loads(info) - return info - def get_torrent_status(core, torrent_id, keys): """Builds the status dictionary and returns it""" status = core.get_torrent_status(torrent_id, keys)