Queueing updates. This breaks torrents.state.

This commit is contained in:
Andrew Resch 2008-03-08 08:19:43 +00:00
parent 54b512a7e0
commit 2dc6df31da
3 changed files with 56 additions and 21 deletions

View File

@ -152,13 +152,12 @@ class Torrent:
# Only set 'Downloading' or 'Seeding' state if not paused # Only set 'Downloading' or 'Seeding' state if not paused
if state == "Downloading" or state == "Seeding": if state == "Downloading" or state == "Seeding":
if self.state == "Queued": # If we're Queued we need to resume the torrent first
self.handle.resume() if self.state != "Queued":
self.state = state
self.torrentqueue.update_order()
if self.handle.is_paused(): if self.handle.is_paused():
state = "Paused" state = "Paused"
else:
return
if state == "Queued" and not self.handle.is_paused(): if state == "Queued" and not self.handle.is_paused():
component.get("TorrentManager").append_not_state_paused(self.torrent_id) component.get("TorrentManager").append_not_state_paused(self.torrent_id)
@ -359,6 +358,23 @@ class Torrent:
return True 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): def move_storage(self, dest):
"""Move a torrent's storage location""" """Move a torrent's storage location"""
try: try:

View File

@ -55,7 +55,7 @@ class TorrentState:
total_uploaded, total_uploaded,
trackers, trackers,
compact, compact,
paused, state,
save_path, save_path,
max_connections, max_connections,
max_upload_slots, max_upload_slots,
@ -74,7 +74,7 @@ class TorrentState:
# Options # Options
self.compact = compact self.compact = compact
self.paused = paused self.state = state
self.save_path = save_path self.save_path = save_path
self.max_connections = max_connections self.max_connections = max_connections
self.max_upload_slots = max_upload_slots self.max_upload_slots = max_upload_slots
@ -171,7 +171,7 @@ class TorrentManager(component.Component):
self.not_state_paused.append(torrent_id) self.not_state_paused.append(torrent_id)
def add(self, filename, filedump=None, options=None, total_uploaded=0, 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""" """Add a torrent to the manager and returns it's torrent_id"""
log.info("Adding torrent: %s", filename) log.info("Adding torrent: %s", filename)
log.debug("options: %s", options) log.debug("options: %s", options)
@ -279,8 +279,10 @@ class TorrentManager(component.Component):
torrent.set_file_priorities(options["file_priorities"]) torrent.set_file_priorities(options["file_priorities"])
# Resume the torrent if needed # Resume the torrent if needed
if options["add_paused"] == False: if state == "Queued":
handle.resume() torrent.state = "Queued"
elif state == "Paused":
torrent.state = "Paused"
# Save the torrent file # Save the torrent file
torrent.save_torrent_file(filedump) torrent.save_torrent_file(filedump)
@ -459,13 +461,19 @@ class TorrentManager(component.Component):
"file_priorities": torrent_state.file_priorities "file_priorities": torrent_state.file_priorities
} }
# We need to resume all non-add_paused torrents after plugin hook # 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( self.add(
torrent_state.filename, torrent_state.filename,
options=options, options=options,
total_uploaded=torrent_state.total_uploaded, total_uploaded=torrent_state.total_uploaded,
trackers=torrent_state.trackers, trackers=torrent_state.trackers,
queue=torrent_state.queue, queue=torrent_state.queue,
state=torrent_state.state,
save_state=False) save_state=False)
except AttributeError, e: except AttributeError, e:
@ -477,9 +485,14 @@ class TorrentManager(component.Component):
self.plugins.run_post_session_load() self.plugins.run_post_session_load()
# Resume any torrents that need to be resumed # Resume any torrents that need to be resumed
log.debug("add_paused: %s", add_paused)
for key in add_paused.keys(): for key in add_paused.keys():
if add_paused[key] == False: if add_paused[key] == False:
self.torrents[key].handle.resume() 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): def save_state(self):
"""Save the state of the TorrentManager to the torrents.state file""" """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.get_status(["total_uploaded"])["total_uploaded"],
torrent.trackers, torrent.trackers,
torrent.compact, torrent.compact,
torrent.get_status(["paused"])["paused"], torrent.state,
torrent.save_path, torrent.save_path,
torrent.max_connections, torrent.max_connections,
torrent.max_upload_slots, torrent.max_upload_slots,

View File

@ -80,6 +80,8 @@ class TorrentQueue(component.Component):
# log.debug("total seeding: %s", len(self.seeding)) # log.debug("total seeding: %s", len(self.seeding))
# log.debug("total downloading: %s", len(self.downloading)) # 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): def update_order(self):
self.update_state_lists() self.update_state_lists()
@ -116,7 +118,8 @@ class TorrentQueue(component.Component):
else: else:
to_unqueue = self.queued_seeding to_unqueue = self.queued_seeding
for (pos, torrent_id) in to_unqueue: 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 self.config["max_active_downloading"] > -1:
if len(self.downloading) > self.config["max_active_downloading"]: if len(self.downloading) > self.config["max_active_downloading"]:
@ -132,7 +135,8 @@ class TorrentQueue(component.Component):
else: else:
to_unqueue = self.queued_downloading to_unqueue = self.queued_downloading
for (pos, torrent_id) in to_unqueue: 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): def set_size(self, size):
"""Clear and set the self.queue list to the length of size""" """Clear and set the self.queue list to the length of size"""
@ -140,9 +144,11 @@ class TorrentQueue(component.Component):
self.queue = [None] * size self.queue = [None] * size
def get_num_seeding(self): def get_num_seeding(self):
self.update_state_lists()
return len(self.seeding) return len(self.seeding)
def get_num_downloading(self): def get_num_downloading(self):
self.update_state_lists()
return len(self.downloading) return len(self.downloading)
def __getitem__(self, torrent_id): def __getitem__(self, torrent_id):