[Core] Fix to async_add_torrent commmit (5d1aff15)

This commit is contained in:
bendikro 2016-04-11 00:42:39 +02:00
parent 5d1aff157e
commit d8c4d8c1aa
3 changed files with 22 additions and 11 deletions

View File

@ -189,7 +189,7 @@ class WebAPITestCase(BaseTestCase, DaemonBase):
yield self.deluge_web.web_api.connect(self.host_id)
filename = os.path.join(os.path.dirname(__file__), "test.torrent")
torrents = [{"path": filename, "options": {"download_location": "/home/deluge/"}}]
self.deluge_web.web_api.add_torrents(torrents)
yield self.deluge_web.web_api.add_torrents(torrents)
ret = yield self.deluge_web.web_api.get_torrent_files("ab570cdd5a17ea1b61e970bb72047de141bce173")
self.assertEquals(ret["type"], "dir")
self.assertEquals(ret["contents"], {u'azcvsupdater_2.6.2.jar':

View File

@ -323,13 +323,6 @@ class TorrentView(ListView, component.Component):
self.treeview.connect("key-press-event", self.on_key_press_event)
self.treeview.connect("columns-changed", self.on_columns_changed_event)
client.register_event_handler("TorrentStateChangedEvent", self.on_torrentstatechanged_event)
client.register_event_handler("TorrentAddedEvent", self.on_torrentadded_event)
client.register_event_handler("TorrentRemovedEvent", self.on_torrentremoved_event)
client.register_event_handler("SessionPausedEvent", self.on_sessionpaused_event)
client.register_event_handler("SessionResumedEvent", self.on_sessionresumed_event)
client.register_event_handler("TorrentQueueChangedEvent", self.on_torrentqueuechanged_event)
self.search_box = SearchBox(self)
self.permanent_status_keys = ["owner"]
self.columns_to_update = []
@ -348,6 +341,13 @@ class TorrentView(ListView, component.Component):
component.get("SessionProxy").get_torrents_status(
{}, status_fields).addCallback(self._on_session_state)
client.register_event_handler("TorrentStateChangedEvent", self.on_torrentstatechanged_event)
client.register_event_handler("TorrentAddedEvent", self.on_torrentadded_event)
client.register_event_handler("TorrentRemovedEvent", self.on_torrentremoved_event)
client.register_event_handler("SessionPausedEvent", self.on_sessionpaused_event)
client.register_event_handler("SessionResumedEvent", self.on_sessionresumed_event)
client.register_event_handler("TorrentQueueChangedEvent", self.on_torrentqueuechanged_event)
def _on_session_state(self, state):
self.add_rows(state)
self.got_state = True
@ -360,6 +360,13 @@ class TorrentView(ListView, component.Component):
def stop(self):
"""Stops the torrentview"""
# We need to clear the liststore
client.deregister_event_handler("TorrentStateChangedEvent", self.on_torrentstatechanged_event)
client.deregister_event_handler("TorrentAddedEvent", self.on_torrentadded_event)
client.deregister_event_handler("TorrentRemovedEvent", self.on_torrentremoved_event)
client.deregister_event_handler("SessionPausedEvent", self.on_sessionpaused_event)
client.deregister_event_handler("SessionResumedEvent", self.on_sessionresumed_event)
client.deregister_event_handler("TorrentQueueChangedEvent", self.on_torrentqueuechanged_event)
if self.treeview.get_selection():
self.treeview.get_selection().unselect_all()
self.liststore.clear()

View File

@ -691,18 +691,22 @@ class WebApi(JSONComponent):
}])
"""
deferreds = []
for torrent in torrents:
if common.is_magnet(torrent["path"]):
log.info("Adding torrent from magnet uri `%s` with options `%r`",
torrent["path"], torrent["options"])
client.core.add_torrent_magnet(torrent["path"], torrent["options"])
d = client.core.add_torrent_magnet(torrent["path"], torrent["options"])
deferreds.append(d)
else:
filename = os.path.basename(torrent["path"])
fdump = base64.encodestring(open(torrent["path"], "rb").read())
log.info("Adding torrent from file `%s` with options `%r`",
filename, torrent["options"])
client.core.add_torrent_file(filename, fdump, torrent["options"])
return True
d = client.core.add_torrent_file(filename, fdump, torrent["options"])
deferreds.append(d)
return DeferredList(deferreds, consumeErrors=False)
@export
def get_hosts(self):