mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-02 22:48:40 +00:00
Queue updates.
This commit is contained in:
parent
81606e3e67
commit
f2065ae344
4 changed files with 114 additions and 71 deletions
|
@ -242,10 +242,6 @@ class Core(
|
||||||
|
|
||||||
# Start the TorrentManager
|
# Start the TorrentManager
|
||||||
self.torrents = TorrentManager(self.session, self.alerts)
|
self.torrents = TorrentManager(self.session, self.alerts)
|
||||||
|
|
||||||
# Register alert handlers
|
|
||||||
self.alerts.register_handler("torrent_paused_alert",
|
|
||||||
self._on_alert_torrent_paused)
|
|
||||||
|
|
||||||
component.start()
|
component.start()
|
||||||
|
|
||||||
|
@ -734,11 +730,3 @@ class Core(
|
||||||
def _on_set_max_upload_slots_global(self, key, value):
|
def _on_set_max_upload_slots_global(self, key, value):
|
||||||
log.debug("max_upload_slots_global set to %s..", value)
|
log.debug("max_upload_slots_global set to %s..", value)
|
||||||
self.session.set_max_uploads(value)
|
self.session.set_max_uploads(value)
|
||||||
|
|
||||||
## Alert handlers ##
|
|
||||||
def _on_alert_torrent_paused(self, alert):
|
|
||||||
log.debug("on_alert_torrent_paused")
|
|
||||||
# Get the torrent_id
|
|
||||||
torrent_id = str(alert.handle.info_hash())
|
|
||||||
# Emit torrent_paused signal
|
|
||||||
self.torrent_paused(torrent_id)
|
|
||||||
|
|
|
@ -152,13 +152,21 @@ 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":
|
||||||
|
self.handle.resume()
|
||||||
|
self.state = state
|
||||||
|
self.torrentqueue.update_order()
|
||||||
|
|
||||||
if self.handle.is_paused():
|
if self.handle.is_paused():
|
||||||
state = "Paused"
|
state = "Paused"
|
||||||
|
|
||||||
if state == "Queued":
|
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)
|
||||||
self.pause()
|
self.handle.pause()
|
||||||
|
|
||||||
|
if state == "Paused":
|
||||||
|
self.torrentqueue.update_order()
|
||||||
|
|
||||||
self.state = state
|
self.state = state
|
||||||
|
|
||||||
def get_eta(self):
|
def get_eta(self):
|
||||||
|
@ -318,26 +326,34 @@ class Torrent:
|
||||||
|
|
||||||
def resume(self):
|
def resume(self):
|
||||||
"""Resumes this torrent"""
|
"""Resumes this torrent"""
|
||||||
#if not self.status.paused:
|
if self.state == "Paused":
|
||||||
# return False
|
|
||||||
|
if self.handle.is_seed():
|
||||||
try:
|
# If the torrent is a seed and there are already the max number of seeds
|
||||||
self.handle.resume()
|
# active, then just change it to a Queued state.
|
||||||
except:
|
if self.torrentqueue.get_num_seeding() >= self.config["max_active_seeding"]:
|
||||||
return False
|
self.set_state("Queued")
|
||||||
|
|
||||||
# Set the state
|
# Update the queuing order if necessary
|
||||||
if self.handle.is_seed():
|
self.torrentqueue.update_order()
|
||||||
self.set_state("Seeding")
|
return True
|
||||||
else:
|
else:
|
||||||
self.set_state("Downloading")
|
if self.torrentqueue.get_num_downloading() >= self.config["max_active_downloading"]:
|
||||||
|
self.set_state("Queued")
|
||||||
status = self.get_status(["total_done", "total_wanted"])
|
|
||||||
|
# Update the queuing order if necessary
|
||||||
# Only delete the .fastresume file if we're still downloading stuff
|
self.torrentqueue.update_order()
|
||||||
if status["total_done"] < status["total_wanted"]:
|
return True
|
||||||
self.delete_fastresume()
|
|
||||||
return True
|
try:
|
||||||
|
self.handle.resume()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if self.handle.is_seed():
|
||||||
|
self.state = "Seeding"
|
||||||
|
else:
|
||||||
|
self.state = "Downloading"
|
||||||
|
|
||||||
def move_storage(self, dest):
|
def move_storage(self, dest):
|
||||||
"""Move a torrent's storage location"""
|
"""Move a torrent's storage location"""
|
||||||
|
|
|
@ -556,8 +556,11 @@ class TorrentManager(component.Component):
|
||||||
# Get the torrent_id
|
# Get the torrent_id
|
||||||
torrent_id = str(alert.handle.info_hash())
|
torrent_id = str(alert.handle.info_hash())
|
||||||
# Set the torrent state
|
# Set the torrent state
|
||||||
|
log.debug("not_state_paused: %s", self.not_state_paused)
|
||||||
if not torrent_id in self.not_state_paused:
|
if not torrent_id in self.not_state_paused:
|
||||||
|
log.debug("Setting state 'Paused'..")
|
||||||
self.torrents[torrent_id].set_state("Paused")
|
self.torrents[torrent_id].set_state("Paused")
|
||||||
|
component.get("SignalManager").emit("torrent_paused", torrent_id)
|
||||||
else:
|
else:
|
||||||
self.not_state_paused.remove(torrent_id)
|
self.not_state_paused.remove(torrent_id)
|
||||||
|
|
||||||
|
|
|
@ -41,73 +41,109 @@ class TorrentQueue(component.Component):
|
||||||
component.Component.__init__(self, "TorrentQueue", depend=["TorrentManager"])
|
component.Component.__init__(self, "TorrentQueue", depend=["TorrentManager"])
|
||||||
# This is a list of torrent_ids in the queueing order
|
# This is a list of torrent_ids in the queueing order
|
||||||
self.queue = []
|
self.queue = []
|
||||||
|
|
||||||
|
# These lists keep track of the torrent states
|
||||||
|
self.seeding = []
|
||||||
|
self.queued_seeding = []
|
||||||
|
self.downloading = []
|
||||||
|
self.queued_downloading = []
|
||||||
|
|
||||||
self.torrents = component.get("TorrentManager")
|
self.torrents = component.get("TorrentManager")
|
||||||
self.config = ConfigManager("core.conf")
|
self.config = ConfigManager("core.conf")
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
seeding = []
|
self.update_state_lists()
|
||||||
queued_seeding = []
|
self.update_max_active()
|
||||||
downloading = []
|
|
||||||
queued_downloading = []
|
def update_state_lists(self):
|
||||||
|
self.seeding = []
|
||||||
|
self.queued_seeding = []
|
||||||
|
self.downloading = []
|
||||||
|
self.queued_downloading = []
|
||||||
|
|
||||||
for torrent_id in self.torrents.get_torrent_list():
|
for torrent_id in self.torrents.get_torrent_list():
|
||||||
if self.torrents[torrent_id].get_status(["state"])["state"] == "Seeding":
|
if self.torrents[torrent_id].get_status(["state"])["state"] == "Seeding":
|
||||||
seeding.append((self.queue.index(torrent_id), torrent_id))
|
self.seeding.append((self.queue.index(torrent_id), torrent_id))
|
||||||
elif self.torrents[torrent_id].get_status(["state"])["state"] == "Downloading":
|
elif self.torrents[torrent_id].get_status(["state"])["state"] == "Downloading":
|
||||||
downloading.append((self.queue.index(torrent_id), torrent_id))
|
self.downloading.append((self.queue.index(torrent_id), torrent_id))
|
||||||
elif self.torrents[torrent_id].get_status(["state"])["state"] == "Queued":
|
elif self.torrents[torrent_id].get_status(["state"])["state"] == "Queued":
|
||||||
if self.torrents[torrent_id].get_status(["is_seed"])["is_seed"]:
|
if self.torrents[torrent_id].get_status(["is_seed"])["is_seed"]:
|
||||||
queued_seeding.append((self.queue.index(torrent_id), torrent_id))
|
self.queued_seeding.append((self.queue.index(torrent_id), torrent_id))
|
||||||
else:
|
else:
|
||||||
queued_downloading.append((self.queue.index(torrent_id), torrent_id))
|
self.queued_downloading.append((self.queue.index(torrent_id), torrent_id))
|
||||||
|
|
||||||
# We need to sort these lists by queue position
|
# We need to sort these lists by queue position
|
||||||
seeding.sort()
|
self.seeding.sort()
|
||||||
downloading.sort()
|
self.downloading.sort()
|
||||||
queued_downloading.sort()
|
self.queued_downloading.sort()
|
||||||
queued_seeding.sort()
|
self.queued_seeding.sort()
|
||||||
|
|
||||||
# log.debug("total seeding: %s", len(seeding))
|
#log.debug("total seeding: %s", len(self.seeding))
|
||||||
# log.debug("total downloading: %s", len(downloading))
|
#log.debug("total downloading: %s", len(self.downloading))
|
||||||
|
|
||||||
|
def update_order(self):
|
||||||
|
self.update_state_lists()
|
||||||
|
#try:
|
||||||
|
# log.debug("max(seeding): %s", max(self.seeding)[0])
|
||||||
|
# log.debug("min(queued_seeding): %s", min(self.queued_seeding)[0])
|
||||||
|
#except:
|
||||||
|
# pass
|
||||||
|
|
||||||
|
if self.seeding != [] and self.queued_seeding != []:
|
||||||
|
if min(self.queued_seeding)[0] < max(self.seeding)[0]:
|
||||||
|
num_to_queue = max(self.seeding)[0] - min(self.queued_seeding)[0]
|
||||||
|
log.debug("queueing: %s", self.seeding[-num_to_queue:])
|
||||||
|
|
||||||
|
for (pos, torrent_id) in self.seeding[-num_to_queue:]:
|
||||||
|
self.torrents[torrent_id].set_state("Queued")
|
||||||
|
|
||||||
|
self.update_state_lists()
|
||||||
|
self.update_max_active()
|
||||||
|
|
||||||
|
def update_max_active(self):
|
||||||
if self.config["max_active_seeding"] > -1:
|
if self.config["max_active_seeding"] > -1:
|
||||||
if len(seeding) > self.config["max_active_seeding"]:
|
if len(self.seeding) > self.config["max_active_seeding"]:
|
||||||
# We need to queue some more torrents because we're over the active limit
|
# We need to queue some more torrents because we're over the active limit
|
||||||
num_to_queue = len(seeding) - self.config["max_active_seeding"]
|
num_to_queue = len(self.seeding) - self.config["max_active_seeding"]
|
||||||
for (pos, torrent_id) in seeding[-num_to_queue:]:
|
for (pos, torrent_id) in self.seeding[-num_to_queue:]:
|
||||||
self.torrents[torrent_id].set_state("Queued")
|
self.torrents[torrent_id].set_state("Queued")
|
||||||
else:
|
else:
|
||||||
# We need to unqueue more torrents if possible
|
# We need to unqueue more torrents if possible
|
||||||
num_to_unqueue = self.config["max_active_seeding"] - len(seeding)
|
num_to_unqueue = self.config["max_active_seeding"] - len(self.seeding)
|
||||||
to_unqueue = []
|
to_unqueue = []
|
||||||
if num_to_unqueue <= len(queued_seeding):
|
if num_to_unqueue <= len(self.queued_seeding):
|
||||||
to_unqueue = queued_seeding[:num_to_unqueue]
|
to_unqueue = self.queued_seeding[:num_to_unqueue]
|
||||||
else:
|
else:
|
||||||
to_unqueue = 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].resume()
|
self.torrents[torrent_id].set_state("Seeding")
|
||||||
|
|
||||||
if self.config["max_active_downloading"] > -1:
|
if self.config["max_active_downloading"] > -1:
|
||||||
if len(downloading) > self.config["max_active_downloading"]:
|
if len(self.downloading) > self.config["max_active_downloading"]:
|
||||||
num_to_queue = len(downloading) - self.config["max_active_downloading"]
|
num_to_queue = len(self.downloading) - self.config["max_active_downloading"]
|
||||||
for (pos, torrent_id) in downloading[-num_to_queue:]:
|
for (pos, torrent_id) in self.downloading[-num_to_queue:]:
|
||||||
self.torrents[torrent_id].set_state("Queued")
|
self.torrents[torrent_id].set_state("Queued")
|
||||||
else:
|
else:
|
||||||
# We need to unqueue more torrents if possible
|
# We need to unqueue more torrents if possible
|
||||||
num_to_unqueue = self.config["max_active_downloading"] - len(downloading)
|
num_to_unqueue = self.config["max_active_downloading"] - len(self.downloading)
|
||||||
to_unqueue = []
|
to_unqueue = []
|
||||||
if num_to_unqueue <= len(queued_downloading):
|
if num_to_unqueue <= len(self.queued_downloading):
|
||||||
to_unqueue = queued_downloading[:num_to_unqueue]
|
to_unqueue = self.queued_downloading[:num_to_unqueue]
|
||||||
else:
|
else:
|
||||||
to_unqueue = 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].resume()
|
self.torrents[torrent_id].set_state("Downloading")
|
||||||
|
|
||||||
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"""
|
||||||
log.debug("Setting queue size to %s..", size)
|
log.debug("Setting queue size to %s..", size)
|
||||||
self.queue = [None] * size
|
self.queue = [None] * size
|
||||||
|
|
||||||
|
def get_num_seeding(self):
|
||||||
|
return len(self.seeding)
|
||||||
|
|
||||||
|
def get_num_downloading(self):
|
||||||
|
return len(self.downloading)
|
||||||
|
|
||||||
def __getitem__(self, torrent_id):
|
def __getitem__(self, torrent_id):
|
||||||
"""Return the queue position of the torrent_id"""
|
"""Return the queue position of the torrent_id"""
|
||||||
|
@ -171,7 +207,7 @@ class TorrentQueue(component.Component):
|
||||||
|
|
||||||
# Pop and insert the torrent_id at index - 1
|
# Pop and insert the torrent_id at index - 1
|
||||||
self.queue.insert(index - 1, self.queue.pop(index))
|
self.queue.insert(index - 1, self.queue.pop(index))
|
||||||
|
self.update_order()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def top(self, torrent_id):
|
def top(self, torrent_id):
|
||||||
|
@ -189,7 +225,7 @@ class TorrentQueue(component.Component):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
self.queue.insert(0, self.queue.pop(index))
|
self.queue.insert(0, self.queue.pop(index))
|
||||||
|
self.update_order()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def down(self, torrent_id):
|
def down(self, torrent_id):
|
||||||
|
@ -208,7 +244,7 @@ class TorrentQueue(component.Component):
|
||||||
|
|
||||||
# Pop and insert the torrent_id at index + 1
|
# Pop and insert the torrent_id at index + 1
|
||||||
self.queue.insert(index + 1, self.queue.pop(index))
|
self.queue.insert(index + 1, self.queue.pop(index))
|
||||||
|
self.update_order()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def bottom(self, torrent_id):
|
def bottom(self, torrent_id):
|
||||||
|
@ -227,5 +263,5 @@ class TorrentQueue(component.Component):
|
||||||
|
|
||||||
# Pop and append the torrent_id
|
# Pop and append the torrent_id
|
||||||
self.append(self.queue.pop(index))
|
self.append(self.queue.pop(index))
|
||||||
|
self.update_order()
|
||||||
return True
|
return True
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue