diff options
author | John Garland <johnnybg+deluge@gmail.com> | 2012-03-10 14:08:25 +1100 |
---|---|---|
committer | John Garland <johnnybg+deluge@gmail.com> | 2012-03-12 23:51:45 +1100 |
commit | 78df634fed4b6c5511bbe7370435bb326fdf2a33 (patch) | |
tree | 5e54f3c56b24a542e6f18ba57040f2122d8c777d | |
parent | e6e677e7d05874d81cc11119fe18828d5f918b97 (diff) | |
download | deluge-78df634fed4b6c5511bbe7370435bb326fdf2a33.tar.gz deluge-78df634fed4b6c5511bbe7370435bb326fdf2a33.tar.bz2 deluge-78df634fed4b6c5511bbe7370435bb326fdf2a33.zip |
Add get_queue_position & use it for sorting ids
-rw-r--r-- | deluge/core/core.py | 8 | ||||
-rw-r--r-- | deluge/core/torrentmanager.py | 4 |
2 files changed, 6 insertions, 6 deletions
diff --git a/deluge/core/core.py b/deluge/core/core.py index de7f266b8..43ac4247b 100644 --- a/deluge/core/core.py +++ b/deluge/core/core.py @@ -762,9 +762,7 @@ class Core(component.Component): def queue_up(self, torrent_ids): log.debug("Attempting to queue %s to up", torrent_ids) #torrent_ids must be sorted before moving. - torrent_ids = list(torrent_ids) - torrent_ids.sort(key = lambda id: self.torrentmanager.torrents[id].get_queue_position()) - for torrent_id in torrent_ids: + for torrent_id in sorted(torrent_ids, key=self.torrentmanager.get_queue_position): try: # If the queue method returns True, then we should emit a signal if self.torrentmanager.queue_up(torrent_id): @@ -776,9 +774,7 @@ class Core(component.Component): def queue_down(self, torrent_ids): log.debug("Attempting to queue %s to down", torrent_ids) #torrent_ids must be sorted before moving. - torrent_ids = list(torrent_ids) - torrent_ids.sort(key = lambda id: -self.torrentmanager.torrents[id].get_queue_position()) - for torrent_id in torrent_ids: + for torrent_id in sorted(torrent_ids, key=self.torrentmanager.get_queue_position, reverse=True): try: # If the queue method returns True, then we should emit a signal if self.torrentmanager.queue_down(torrent_id): diff --git a/deluge/core/torrentmanager.py b/deluge/core/torrentmanager.py index 2539532bf..49db2c112 100644 --- a/deluge/core/torrentmanager.py +++ b/deluge/core/torrentmanager.py @@ -864,6 +864,10 @@ class TorrentManager(component.Component): except OSError as (errno, strerror): log.debug("Cannot Remove Folder: %s (ErrNo %s)", strerror, errno) + def get_queue_position(self, torrent_id): + """Get queue position of torrent""" + return self.torrents[torrent_id].get_queue_position() + def queue_top(self, torrent_id): """Queue torrent to top""" if self.torrents[torrent_id].get_queue_position() == 0: |