mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-13 13:05:37 +00:00
[Core] Fix core.remove_torrents return value on error
This commit is contained in:
parent
43edea01b7
commit
14b576e411
@ -346,10 +346,13 @@ class Core(component.Component):
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
torrent_ids (list): The torrent IDs to remove.
|
torrent_ids (list): The torrent IDs to remove.
|
||||||
remove_data (bool, optional): If True, also remove the downloaded data.
|
remove_data (bool): If True, also remove the downloaded data.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
list: a list containing all the errors, empty list if no errors occured
|
list of tuples: A list tuples containing all the errors, empty list if no errors occured
|
||||||
|
tuple format:
|
||||||
|
0: str: torrent-id
|
||||||
|
1: str: Error message
|
||||||
|
|
||||||
"""
|
"""
|
||||||
log.info("Removing %d torrents from core.", len(torrent_ids))
|
log.info("Removing %d torrents from core.", len(torrent_ids))
|
||||||
@ -360,9 +363,11 @@ class Core(component.Component):
|
|||||||
try:
|
try:
|
||||||
self.torrentmanager.remove(torrent_id, remove_data=remove_data, save_state=False)
|
self.torrentmanager.remove(torrent_id, remove_data=remove_data, save_state=False)
|
||||||
except InvalidTorrentError as ex:
|
except InvalidTorrentError as ex:
|
||||||
errors.append((torrent_id, ex))
|
errors.append((torrent_id, str(ex)))
|
||||||
# Save the session state
|
# Save the session state
|
||||||
self.torrentmanager.save_state()
|
self.torrentmanager.save_state()
|
||||||
|
if errors:
|
||||||
|
log.warn("Failed to remove %d of %d torrents.", len(errors), len(torrent_ids))
|
||||||
return errors
|
return errors
|
||||||
return task.deferLater(reactor, 0, do_remove_torrents)
|
return task.deferLater(reactor, 0, do_remove_torrents)
|
||||||
|
|
||||||
|
@ -202,14 +202,7 @@ class CoreTestCase(BaseTestCase):
|
|||||||
self.assertEquals(len(self.core.get_session_state()), 0)
|
self.assertEquals(len(self.core.get_session_state()), 0)
|
||||||
|
|
||||||
def test_remove_torrent_invalid(self):
|
def test_remove_torrent_invalid(self):
|
||||||
d = self.core.remove_torrents(["torrentidthatdoesntexist"], True)
|
self.assertRaises(InvalidTorrentError, self.core.remove_torrent, "torrentidthatdoesntexist", True)
|
||||||
|
|
||||||
def test_true(val):
|
|
||||||
self.assertTrue(val[0][0] == "torrentidthatdoesntexist")
|
|
||||||
|
|
||||||
self.assertTrue(isinstance(val[0][1], InvalidTorrentError))
|
|
||||||
d.addCallback(test_true)
|
|
||||||
return d
|
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_remove_torrents(self):
|
def test_remove_torrents(self):
|
||||||
@ -234,16 +227,10 @@ class CoreTestCase(BaseTestCase):
|
|||||||
options = {}
|
options = {}
|
||||||
filename = os.path.join(os.path.dirname(__file__), "test.torrent")
|
filename = os.path.join(os.path.dirname(__file__), "test.torrent")
|
||||||
torrent_id = yield self.core.add_torrent_file(filename, base64.encodestring(open(filename).read()), options)
|
torrent_id = yield self.core.add_torrent_file(filename, base64.encodestring(open(filename).read()), options)
|
||||||
d = self.core.remove_torrents(["invalidid1", "invalidid2", torrent_id], False)
|
val = yield self.core.remove_torrents(["invalidid1", "invalidid2", torrent_id], False)
|
||||||
|
self.assertEqual(len(val), 2)
|
||||||
def test_ret(val):
|
self.assertEqual(val[0], ('invalidid1', "torrent_id 'invalidid1' not in session."))
|
||||||
self.assertTrue(len(val) == 2)
|
self.assertEqual(val[1], ('invalidid2', "torrent_id 'invalidid2' not in session."))
|
||||||
self.assertTrue(val[0][0] == "invalidid1")
|
|
||||||
self.assertTrue(isinstance(val[0][1], InvalidTorrentError))
|
|
||||||
self.assertTrue(val[1][0] == "invalidid2")
|
|
||||||
self.assertTrue(isinstance(val[1][1], InvalidTorrentError))
|
|
||||||
d.addCallback(test_ret)
|
|
||||||
yield d
|
|
||||||
|
|
||||||
def test_get_session_status(self):
|
def test_get_session_status(self):
|
||||||
status = self.core.get_session_status(["upload_rate", "download_rate"])
|
status = self.core.get_session_status(["upload_rate", "download_rate"])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user