More queue updates.

This commit is contained in:
Andrew Resch 2008-03-07 02:27:34 +00:00
parent cd2bfe8a62
commit 81606e3e67
3 changed files with 29 additions and 8 deletions

View File

@ -154,7 +154,11 @@ class Torrent:
if state == "Downloading" or state == "Seeding":
if self.handle.is_paused():
state = "Paused"
if state == "Queued":
component.get("TorrentManager").append_not_state_paused(self.torrent_id)
self.pause()
self.state = state
def get_eta(self):
@ -300,6 +304,10 @@ class Torrent:
def pause(self):
"""Pause this torrent"""
if self.state == "Queued":
self.set_state("Paused")
return True
try:
self.handle.pause()
except Exception, e:
@ -310,8 +318,8 @@ class Torrent:
def resume(self):
"""Resumes this torrent"""
if self.state != "Paused":
return False
#if not self.status.paused:
# return False
try:
self.handle.resume()

View File

@ -108,6 +108,9 @@ class TorrentManager(component.Component):
# Create the torrents dict { torrent_id: Torrent }
self.torrents = {}
# List of torrents to note set state 'Paused' on lt alert
self.not_state_paused = []
# Register set functions
self.config.register_set_function("max_connections_per_torrent",
self.on_set_max_connections_per_torrent)
@ -160,7 +163,13 @@ class TorrentManager(component.Component):
def get_torrent_list(self):
"""Returns a list of torrent_ids"""
return self.torrents.keys()
def append_not_state_paused(self, torrent_id):
"""Appends to a list of torrents that we will not set state Paused to
when we receive the paused alert from libtorrent. The torrents are removed
from this list once we receive the alert they have been paused in libtorrent."""
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):
"""Add a torrent to the manager and returns it's torrent_id"""
@ -547,7 +556,11 @@ class TorrentManager(component.Component):
# Get the torrent_id
torrent_id = str(alert.handle.info_hash())
# Set the torrent state
self.torrents[torrent_id].set_state("Paused")
if not torrent_id in self.not_state_paused:
self.torrents[torrent_id].set_state("Paused")
else:
self.not_state_paused.remove(torrent_id)
# Write the fastresume file
self.torrents[torrent_id].write_fastresume()

View File

@ -86,7 +86,7 @@ class TorrentQueue(component.Component):
else:
to_unqueue = queued_seeding
for (pos, torrent_id) in to_unqueue:
self.torrents[torrent_id].set_state("Seeding")
self.torrents[torrent_id].resume()
if self.config["max_active_downloading"] > -1:
if len(downloading) > self.config["max_active_downloading"]:
@ -102,8 +102,8 @@ class TorrentQueue(component.Component):
else:
to_unqueue = queued_downloading
for (pos, torrent_id) in to_unqueue:
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)