From 3176b877a415edf0119fef3deeeddde9361a590b Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Wed, 28 Jun 2017 22:30:16 +0100 Subject: [PATCH] [Core] Add methods pause_torrents & resume_torrents --- deluge/core/core.py | 33 ++++++++++++++++++++++++++------- deluge/core/torrent.py | 4 +--- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/deluge/core/core.py b/deluge/core/core.py index db20f6d29..2662ad221 100644 --- a/deluge/core/core.py +++ b/deluge/core/core.py @@ -600,11 +600,20 @@ class Core(component.Component): self.torrentmanager[torrent_id].force_reannounce() @export - def pause_torrent(self, torrent_ids): - log.debug('Pausing: %s', torrent_ids) + def pause_torrent(self, torrent_id): + """Pauses a torrent""" + log.debug('Pausing: %s', torrent_id) + if not isinstance(torrent_id, str if not PY2 else basestring): + self.pause_torrents(torrent_id) + self.torrentmanager[torrent_id].pause() + + @export + def pause_torrents(self, torrent_ids=None): + """Pauses a list of torrents""" + if not torrent_ids: + torrent_ids = self.torrentmanager.get_torrent_list() for torrent_id in torrent_ids: - if not self.torrentmanager[torrent_id].pause(): - log.warning('Error pausing torrent %s', torrent_id) + self.pause_torrent(torrent_id) @export def connect_peer(self, torrent_id, ip, port): @@ -636,10 +645,20 @@ class Core(component.Component): component.get('EventManager').emit(SessionResumedEvent()) @export - def resume_torrent(self, torrent_ids): - log.debug('Resuming: %s', torrent_ids) + def resume_torrent(self, torrent_id): + """Resumes a torrent""" + log.debug('Resuming: %s', torrent_id) + if not isinstance(torrent_id, str if not PY2 else basestring): + self.resume_torrents(torrent_id) + self.torrentmanager[torrent_id].resume() + + @export + def resume_torrents(self, torrent_ids=None): + """Resumes a list of torrents""" + if not torrent_ids: + torrent_ids = self.torrentmanager.get_torrent_list() for torrent_id in torrent_ids: - self.torrentmanager[torrent_id].resume() + self.resume_torrent(torrent_id) def create_torrent_status(self, torrent_id, torrent_keys, plugin_keys, diff=False, update=False, all_keys=False): try: diff --git a/deluge/core/torrent.py b/deluge/core/torrent.py index fcb001b65..e9d3e540c 100644 --- a/deluge/core/torrent.py +++ b/deluge/core/torrent.py @@ -1081,7 +1081,7 @@ class Torrent(object): # Turn off auto-management so the torrent will not be unpaused by lt queueing self.handle.auto_managed(False) if self.state == 'Error': - return False + log.debug('Unable to pause torrent while in Error state') elif self.status.paused: # This torrent was probably paused due to being auto managed by lt # Since we turned auto_managed off, we should update the state which should @@ -1094,8 +1094,6 @@ class Torrent(object): self.handle.pause() except RuntimeError as ex: log.debug('Unable to pause torrent: %s', ex) - return False - return True def resume(self): """Resumes this torrent."""