From 2dc6df31da3618e3b4199615993f4ddda1ac7b11 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Sat, 8 Mar 2008 08:19:43 +0000 Subject: [PATCH] Queueing updates. This breaks torrents.state. --- deluge/core/torrent.py | 32 ++++++++++++++++++++++++-------- deluge/core/torrentmanager.py | 27 ++++++++++++++++++++------- deluge/core/torrentqueue.py | 18 ++++++++++++------ 3 files changed, 56 insertions(+), 21 deletions(-) diff --git a/deluge/core/torrent.py b/deluge/core/torrent.py index de66c6548..935acba97 100644 --- a/deluge/core/torrent.py +++ b/deluge/core/torrent.py @@ -152,14 +152,13 @@ class Torrent: # Only set 'Downloading' or 'Seeding' state if not paused if state == "Downloading" or state == "Seeding": - if self.state == "Queued": - self.handle.resume() - self.state = state - self.torrentqueue.update_order() + # If we're Queued we need to resume the torrent first + if self.state != "Queued": + if self.handle.is_paused(): + state = "Paused" + else: + return - if self.handle.is_paused(): - state = "Paused" - if state == "Queued" and not self.handle.is_paused(): component.get("TorrentManager").append_not_state_paused(self.torrent_id) self.handle.pause() @@ -358,7 +357,24 @@ class Torrent: self.state = "Downloading" return True - + + elif self.state == "Queued": + if self.handle.is_seed(): + if self.torrentqueue.get_num_seeding() < self.config["max_active_seeding"]: + self.handle.resume() + self.state = "Seeding" + self.torrentqueue.update_order() + else: + return False + else: + if self.torrentqueue.get_num_downloading() < self.config["max_active_downloading"]: + self.handle.resume() + self.state = "Downloading" + self.torrentqueue.update_order() + else: + return False + + def move_storage(self, dest): """Move a torrent's storage location""" try: diff --git a/deluge/core/torrentmanager.py b/deluge/core/torrentmanager.py index 1e5a8fb9a..eea5ce245 100644 --- a/deluge/core/torrentmanager.py +++ b/deluge/core/torrentmanager.py @@ -55,7 +55,7 @@ class TorrentState: total_uploaded, trackers, compact, - paused, + state, save_path, max_connections, max_upload_slots, @@ -74,7 +74,7 @@ class TorrentState: # Options self.compact = compact - self.paused = paused + self.state = state self.save_path = save_path self.max_connections = max_connections self.max_upload_slots = max_upload_slots @@ -171,7 +171,7 @@ class TorrentManager(component.Component): self.not_state_paused.append(torrent_id) def add(self, filename, filedump=None, options=None, total_uploaded=0, - trackers=None, queue=-1, save_state=True): + trackers=None, queue=-1, state=None, save_state=True): """Add a torrent to the manager and returns it's torrent_id""" log.info("Adding torrent: %s", filename) log.debug("options: %s", options) @@ -279,8 +279,10 @@ class TorrentManager(component.Component): torrent.set_file_priorities(options["file_priorities"]) # Resume the torrent if needed - if options["add_paused"] == False: - handle.resume() + if state == "Queued": + torrent.state = "Queued" + elif state == "Paused": + torrent.state = "Paused" # Save the torrent file torrent.save_torrent_file(filedump) @@ -459,13 +461,19 @@ class TorrentManager(component.Component): "file_priorities": torrent_state.file_priorities } # We need to resume all non-add_paused torrents after plugin hook - add_paused[torrent_state.torrent_id] = torrent_state.paused + if torrent_state.state == "Paused" or torrent_state.state == "Queued": + log.debug("torrent state: %s", torrent_state.state) + add_paused[torrent_state.torrent_id] = True + else: + add_paused[torrent_state.torrent_id] = False + self.add( torrent_state.filename, options=options, total_uploaded=torrent_state.total_uploaded, trackers=torrent_state.trackers, queue=torrent_state.queue, + state=torrent_state.state, save_state=False) except AttributeError, e: @@ -477,9 +485,14 @@ class TorrentManager(component.Component): self.plugins.run_post_session_load() # Resume any torrents that need to be resumed + log.debug("add_paused: %s", add_paused) for key in add_paused.keys(): if add_paused[key] == False: self.torrents[key].handle.resume() + if self.torrents[key].get_status(["is_seed"])["is_seed"]: + self.torrents[key].state = "Seeding" + else: + self.torrents[key].state = "Downloading" def save_state(self): """Save the state of the TorrentManager to the torrents.state file""" @@ -492,7 +505,7 @@ class TorrentManager(component.Component): torrent.get_status(["total_uploaded"])["total_uploaded"], torrent.trackers, torrent.compact, - torrent.get_status(["paused"])["paused"], + torrent.state, torrent.save_path, torrent.max_connections, torrent.max_upload_slots, diff --git a/deluge/core/torrentqueue.py b/deluge/core/torrentqueue.py index 978cfee8c..02123e824 100644 --- a/deluge/core/torrentqueue.py +++ b/deluge/core/torrentqueue.py @@ -78,8 +78,10 @@ class TorrentQueue(component.Component): self.queued_downloading.sort() self.queued_seeding.sort() - #log.debug("total seeding: %s", len(self.seeding)) - #log.debug("total downloading: %s", len(self.downloading)) +# log.debug("total seeding: %s", len(self.seeding)) +# log.debug("total downloading: %s", len(self.downloading)) +# log.debug("queued seeding: %s", len(self.queued_seeding)) +# log.debug("queued downloading: %s", len(self.queued_downloading)) def update_order(self): self.update_state_lists() @@ -100,7 +102,7 @@ class TorrentQueue(component.Component): self.update_state_lists() self.update_max_active() - def update_max_active(self): + def update_max_active(self): if self.config["max_active_seeding"] > -1: if len(self.seeding) > self.config["max_active_seeding"]: # We need to queue some more torrents because we're over the active limit @@ -116,7 +118,8 @@ class TorrentQueue(component.Component): else: to_unqueue = self.queued_seeding for (pos, torrent_id) in to_unqueue: - self.torrents[torrent_id].set_state("Seeding") + #self.torrents[torrent_id].set_state("Seeding") + self.torrents[torrent_id].resume() if self.config["max_active_downloading"] > -1: if len(self.downloading) > self.config["max_active_downloading"]: @@ -132,17 +135,20 @@ class TorrentQueue(component.Component): else: to_unqueue = self.queued_downloading for (pos, torrent_id) in to_unqueue: - self.torrents[torrent_id].set_state("Downloading") - + #self.torrents[torrent_id].set_state("Downloading") + self.torrents[torrent_id].resume() + def set_size(self, size): """Clear and set the self.queue list to the length of size""" log.debug("Setting queue size to %s..", size) self.queue = [None] * size def get_num_seeding(self): + self.update_state_lists() return len(self.seeding) def get_num_downloading(self): + self.update_state_lists() return len(self.downloading) def __getitem__(self, torrent_id):