[Console] Refactor callbacks and cleanup main
This commit is contained in:
parent
22f74b60ce
commit
ae22a52f2f
|
@ -365,27 +365,23 @@ deluge-console.exe "add -p c:\\mytorrents c:\\new.torrent"
|
||||||
self.started_deferred.callback(True)
|
self.started_deferred.callback(True)
|
||||||
|
|
||||||
# Register event handlers to keep the torrent list up-to-date
|
# Register event handlers to keep the torrent list up-to-date
|
||||||
client.register_event_handler('TorrentAddedEvent', self.on_torrent_added_event)
|
client.register_event_handler('TorrentAddedEvent', self.on_torrent_added)
|
||||||
client.register_event_handler(
|
client.register_event_handler('TorrentRemovedEvent', self.on_torrent_removed)
|
||||||
'TorrentRemovedEvent', self.on_torrent_removed_event
|
|
||||||
)
|
|
||||||
|
|
||||||
def on_torrent_added_event(self, event, from_state=False):
|
@defer.inlineCallbacks
|
||||||
def on_torrent_status(status):
|
def on_torrent_added(self, event, from_state=False):
|
||||||
self.torrents.append((event, status['name']))
|
status = yield client.core.get_torrent_status(event, ['name'])
|
||||||
|
self.torrents.append((event, status['name']))
|
||||||
|
|
||||||
client.core.get_torrent_status(event, ['name']).addCallback(on_torrent_status)
|
def on_torrent_removed(self, event):
|
||||||
|
|
||||||
def on_torrent_removed_event(self, event):
|
|
||||||
for index, (tid, name) in enumerate(self.torrents):
|
for index, (tid, name) in enumerate(self.torrents):
|
||||||
if event == tid:
|
if event == tid:
|
||||||
del self.torrents[index]
|
del self.torrents[index]
|
||||||
|
|
||||||
def match_torrents(self, strings):
|
def match_torrents(self, strings):
|
||||||
torrent_ids = []
|
return list(
|
||||||
for s in strings:
|
{torrent for string in strings for torrent in self.match_torrent(string)}
|
||||||
torrent_ids.extend(self.match_torrent(s))
|
)
|
||||||
return list(set(torrent_ids))
|
|
||||||
|
|
||||||
def match_torrent(self, string):
|
def match_torrent(self, string):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue