diff options
author | Calum Lind <calumlind+deluge@gmail.com> | 2023-02-27 13:25:05 +0000 |
---|---|---|
committer | Calum Lind <calumlind+deluge@gmail.com> | 2023-02-27 17:38:59 +0000 |
commit | ae22a52f2f4c7b3d41b0b81c0fbc19a5b38da822 (patch) | |
tree | 12ce9473fde3b178b4e43eeac0ee89f0724744a4 | |
parent | 22f74b60ce285579af2848889b18ee3d1721312c (diff) | |
download | deluge-ae22a52f2f4c7b3d41b0b81c0fbc19a5b38da822.tar.gz deluge-ae22a52f2f4c7b3d41b0b81c0fbc19a5b38da822.tar.bz2 deluge-ae22a52f2f4c7b3d41b0b81c0fbc19a5b38da822.zip |
[Console] Refactor callbacks and cleanup main
-rw-r--r-- | deluge/ui/console/main.py | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/deluge/ui/console/main.py b/deluge/ui/console/main.py index af89dbf44..eb7cf6ee4 100644 --- a/deluge/ui/console/main.py +++ b/deluge/ui/console/main.py @@ -365,27 +365,23 @@ deluge-console.exe "add -p c:\\mytorrents c:\\new.torrent" self.started_deferred.callback(True) # 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( - 'TorrentRemovedEvent', self.on_torrent_removed_event - ) + client.register_event_handler('TorrentAddedEvent', self.on_torrent_added) + client.register_event_handler('TorrentRemovedEvent', self.on_torrent_removed) - def on_torrent_added_event(self, event, from_state=False): - def on_torrent_status(status): - self.torrents.append((event, status['name'])) - - client.core.get_torrent_status(event, ['name']).addCallback(on_torrent_status) + @defer.inlineCallbacks + def on_torrent_added(self, event, from_state=False): + status = yield client.core.get_torrent_status(event, ['name']) + self.torrents.append((event, status['name'])) - def on_torrent_removed_event(self, event): + def on_torrent_removed(self, event): for index, (tid, name) in enumerate(self.torrents): if event == tid: del self.torrents[index] def match_torrents(self, strings): - torrent_ids = [] - for s in strings: - torrent_ids.extend(self.match_torrent(s)) - return list(set(torrent_ids)) + return list( + {torrent for string in strings for torrent in self.match_torrent(string)} + ) def match_torrent(self, string): """ |