mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-02 22:48:40 +00:00
State fixes.
This commit is contained in:
parent
0b63f0b3b4
commit
3ac9af0486
3 changed files with 56 additions and 39 deletions
|
@ -47,7 +47,16 @@ LT_TORRENT_STATE = {
|
||||||
"Finished": 5,
|
"Finished": 5,
|
||||||
"Seeding": 6,
|
"Seeding": 6,
|
||||||
"Allocating": 7,
|
"Allocating": 7,
|
||||||
"Paused": 8
|
"Paused": 8,
|
||||||
|
0: "Queued",
|
||||||
|
1: "Checking",
|
||||||
|
2: "Connecting",
|
||||||
|
3: "Downloading Metadata",
|
||||||
|
4: "Downloading",
|
||||||
|
5: "Finished",
|
||||||
|
6: "Seeding",
|
||||||
|
7: "Allocating",
|
||||||
|
8: "Paused"
|
||||||
}
|
}
|
||||||
|
|
||||||
TORRENT_STATE = [
|
TORRENT_STATE = [
|
||||||
|
|
|
@ -72,17 +72,13 @@ class Torrent:
|
||||||
# Status message holds error info about the torrent
|
# Status message holds error info about the torrent
|
||||||
self.statusmsg = "OK"
|
self.statusmsg = "OK"
|
||||||
|
|
||||||
|
# The torrents state
|
||||||
|
self.state = ""
|
||||||
|
|
||||||
# Holds status info so that we don't need to keep getting it from lt
|
# Holds status info so that we don't need to keep getting it from lt
|
||||||
self.status = self.handle.status()
|
self.status = self.handle.status()
|
||||||
self.torrent_info = self.handle.get_torrent_info()
|
self.torrent_info = self.handle.get_torrent_info()
|
||||||
|
|
||||||
# Set the initial state
|
|
||||||
self.state = "Checking"
|
|
||||||
if self.handle.is_seed():
|
|
||||||
self.state = "Seeding"
|
|
||||||
else:
|
|
||||||
self.state = "Downloading"
|
|
||||||
|
|
||||||
# Various torrent options
|
# Various torrent options
|
||||||
self.max_connections = -1
|
self.max_connections = -1
|
||||||
self.max_upload_slots = -1
|
self.max_upload_slots = -1
|
||||||
|
@ -160,6 +156,21 @@ class Torrent:
|
||||||
self.file_priorities = file_priorities
|
self.file_priorities = file_priorities
|
||||||
self.handle.prioritize_files(file_priorities)
|
self.handle.prioritize_files(file_priorities)
|
||||||
|
|
||||||
|
def set_state_based_on_ltstate(self):
|
||||||
|
"""Updates the state based on what libtorrent's state for the torrent is"""
|
||||||
|
# Set the initial state based on the lt state
|
||||||
|
LTSTATE = deluge.common.LT_TORRENT_STATE
|
||||||
|
ltstate = self.handle.status().state
|
||||||
|
if ltstate == LTSTATE["Queued"] or ltstate == LTSTATE["Checking"]:
|
||||||
|
self.set_state("Checking")
|
||||||
|
elif ltstate == LTSTATE["Connecting"] or ltstate == LTSTATE["Downloading"] or\
|
||||||
|
ltstate == LTSTATE["Downloading Metadata"]:
|
||||||
|
self.set_state("Downloading")
|
||||||
|
elif ltstate == LTSTATE["Finished"] or ltstate == LTSTATE["Seeding"]:
|
||||||
|
self.set_state("Seeding")
|
||||||
|
elif ltstate == LTSTATE["Allocating"]:
|
||||||
|
self.set_state("Allocating")
|
||||||
|
|
||||||
def set_state(self, state):
|
def set_state(self, state):
|
||||||
"""Accepts state strings, ie, "Paused", "Seeding", etc."""
|
"""Accepts state strings, ie, "Paused", "Seeding", etc."""
|
||||||
|
|
||||||
|
@ -388,7 +399,7 @@ class Torrent:
|
||||||
# Reset the status message just in case of resuming an Error'd torrent
|
# Reset the status message just in case of resuming an Error'd torrent
|
||||||
self.set_status_message("OK")
|
self.set_status_message("OK")
|
||||||
|
|
||||||
if self.handle.is_seed():
|
if self.handle.is_finished():
|
||||||
# If the torrent has already reached it's 'stop_seed_ratio' then do not do anything
|
# If the torrent has already reached it's 'stop_seed_ratio' then do not do anything
|
||||||
if self.config["stop_seed_at_ratio"]:
|
if self.config["stop_seed_at_ratio"]:
|
||||||
if self.get_ratio() >= self.config["stop_seed_ratio"]:
|
if self.get_ratio() >= self.config["stop_seed_ratio"]:
|
||||||
|
@ -416,17 +427,17 @@ class Torrent:
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if self.handle.is_seed():
|
if self.handle.is_finished():
|
||||||
self.state = "Seeding"
|
self.state = "Seeding"
|
||||||
|
else:
|
||||||
# Only delete the .fastresume file if we're still downloading stuff
|
# Only delete the .fastresume file if we're still downloading stuff
|
||||||
self.delete_fastresume()
|
self.delete_fastresume()
|
||||||
else:
|
|
||||||
self.state = "Downloading"
|
self.state = "Downloading"
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
elif self.state == "Queued":
|
elif self.state == "Queued":
|
||||||
if self.handle.is_seed():
|
if self.handle.is_finished():
|
||||||
if self.torrentqueue.get_num_seeding() < self.config["max_active_seeding"] or\
|
if self.torrentqueue.get_num_seeding() < self.config["max_active_seeding"] or\
|
||||||
self.config["max_active_seeding"] == -1:
|
self.config["max_active_seeding"] == -1:
|
||||||
self.handle.resume()
|
self.handle.resume()
|
||||||
|
|
|
@ -157,7 +157,7 @@ class TorrentManager(component.Component):
|
||||||
self.save_state()
|
self.save_state()
|
||||||
for key in self.torrents.keys():
|
for key in self.torrents.keys():
|
||||||
if not self.torrents[key].handle.is_paused() and \
|
if not self.torrents[key].handle.is_paused() and \
|
||||||
not self.torrents[key].handle.is_seed():
|
not self.torrents[key].handle.is_finished():
|
||||||
if self.torrents[key].compact:
|
if self.torrents[key].compact:
|
||||||
try:
|
try:
|
||||||
self.torrents[key].pause()
|
self.torrents[key].pause()
|
||||||
|
@ -301,15 +301,19 @@ class TorrentManager(component.Component):
|
||||||
log.debug("set file priorities: %s", options["file_priorities"])
|
log.debug("set file priorities: %s", options["file_priorities"])
|
||||||
torrent.set_file_priorities(options["file_priorities"])
|
torrent.set_file_priorities(options["file_priorities"])
|
||||||
|
|
||||||
|
log.debug("state: %s", state)
|
||||||
|
|
||||||
# Resume the torrent if needed
|
# Resume the torrent if needed
|
||||||
if state == "Queued":
|
if state == "Queued":
|
||||||
torrent.state = "Queued"
|
torrent.set_state("Queued")
|
||||||
elif state == "Paused" or state == "Error":
|
elif state == "Paused" or state == "Error":
|
||||||
torrent.state = "Paused"
|
torrent.set_state("Paused")
|
||||||
if state == None and not options["add_paused"]:
|
if state == None and not options["add_paused"]:
|
||||||
torrent.handle.resume()
|
torrent.handle.resume()
|
||||||
|
# We set the state based on libtorrent's state
|
||||||
|
torrent.set_state_based_on_ltstate()
|
||||||
if state == None and options["add_paused"]:
|
if state == None and options["add_paused"]:
|
||||||
torrent.state = "Paused"
|
torrent.set_state("Paused")
|
||||||
|
|
||||||
# Emit the torrent_added signal
|
# Emit the torrent_added signal
|
||||||
self.signals.emit("torrent_added", torrent.torrent_id)
|
self.signals.emit("torrent_added", torrent.torrent_id)
|
||||||
|
@ -472,7 +476,7 @@ class TorrentManager(component.Component):
|
||||||
log.warning("Unable to load state file.")
|
log.warning("Unable to load state file.")
|
||||||
|
|
||||||
# Try to add the torrents in the state to the session
|
# Try to add the torrents in the state to the session
|
||||||
add_paused = {}
|
resume_torrents = []
|
||||||
# First lets clear the queue and make it the correct length.. This will
|
# First lets clear the queue and make it the correct length.. This will
|
||||||
# help with inserting values at the right position.
|
# help with inserting values at the right position.
|
||||||
self.queue.set_size(len(state.torrents))
|
self.queue.set_size(len(state.torrents))
|
||||||
|
@ -503,11 +507,8 @@ 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
|
||||||
if torrent_state.state == "Paused" or torrent_state.state == "Queued" or torrent_state.state == "Error":
|
if torrent_state.state not in ["Paused", "Queued", "Error"]:
|
||||||
log.debug("torrent state: %s", torrent_state.state)
|
resume_torrents.append(torrent_state.torrent_id)
|
||||||
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,
|
||||||
|
@ -527,15 +528,10 @@ 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 torrent_id in resume_torrents:
|
||||||
for key in add_paused.keys():
|
self.torrents[torrent_id].handle.resume()
|
||||||
if add_paused[key] == False:
|
self.torrents[torrent_id].set_state_based_on_ltstate()
|
||||||
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"""
|
||||||
state = TorrentManagerState()
|
state = TorrentManagerState()
|
||||||
|
@ -608,12 +604,13 @@ class TorrentManager(component.Component):
|
||||||
if self.config["queue_finished_to_bottom"]:
|
if self.config["queue_finished_to_bottom"]:
|
||||||
self.queue.bottom(torrent_id)
|
self.queue.bottom(torrent_id)
|
||||||
|
|
||||||
# Set the torrent state
|
# Set the torrent state if not paused
|
||||||
if self.queue.get_num_seeding() < self.config["max_active_seeding"] or\
|
if not self.torrents[torrent_id].handle.is_paused():
|
||||||
self.config["max_active_seeding"] == -1:
|
if self.queue.get_num_seeding() < self.config["max_active_seeding"] or\
|
||||||
self.torrents[torrent_id].set_state("Seeding")
|
self.config["max_active_seeding"] == -1:
|
||||||
else:
|
self.torrents[torrent_id].set_state("Seeding")
|
||||||
self.torrents[torrent_id].set_state("Queued")
|
else:
|
||||||
|
self.torrents[torrent_id].set_state("Queued")
|
||||||
|
|
||||||
# Write the fastresume file
|
# Write the fastresume file
|
||||||
self.torrents[torrent_id].write_fastresume()
|
self.torrents[torrent_id].write_fastresume()
|
||||||
|
@ -640,7 +637,7 @@ class TorrentManager(component.Component):
|
||||||
torrent_id = str(alert.handle.info_hash())
|
torrent_id = str(alert.handle.info_hash())
|
||||||
# Set the torrent state
|
# Set the torrent state
|
||||||
if not self.torrents[torrent_id].handle.is_paused():
|
if not self.torrents[torrent_id].handle.is_paused():
|
||||||
if self.torrents[torrent_id].handle.is_seed():
|
if self.torrents[torrent_id].handle.is_finished():
|
||||||
self.torrents[torrent_id].set_state("Seeding")
|
self.torrents[torrent_id].set_state("Seeding")
|
||||||
else:
|
else:
|
||||||
self.torrents[torrent_id].set_state("Downloading")
|
self.torrents[torrent_id].set_state("Downloading")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue