Fix adding torrents and setting proper state on load.
This commit is contained in:
parent
723fd76d84
commit
b3f9785b20
|
@ -48,6 +48,7 @@ class Torrent:
|
||||||
"""
|
"""
|
||||||
def __init__(self, filename, handle, compact, save_path, total_uploaded=0,
|
def __init__(self, filename, handle, compact, save_path, total_uploaded=0,
|
||||||
trackers=None):
|
trackers=None):
|
||||||
|
log.debug("Creating torrent object %s", str(handle.info_hash()))
|
||||||
# Get the core config
|
# Get the core config
|
||||||
self.config = ConfigManager("core.conf")
|
self.config = ConfigManager("core.conf")
|
||||||
|
|
||||||
|
@ -67,20 +68,17 @@ class Torrent:
|
||||||
self.compact = compact
|
self.compact = compact
|
||||||
# Where the torrent is being saved to
|
# Where the torrent is being saved to
|
||||||
self.save_path = save_path
|
self.save_path = save_path
|
||||||
# The state of the torrent
|
|
||||||
self.state = "Paused"
|
|
||||||
|
|
||||||
# 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.torrent_info()
|
self.torrent_info = self.handle.torrent_info()
|
||||||
|
|
||||||
# Set the initial state
|
# Set the initial state
|
||||||
if self.status.state == deluge.common.LT_TORRENT_STATE["Allocating"]:
|
self.state = "Checking"
|
||||||
self.set_state("Allocating")
|
if self.handle.is_seed():
|
||||||
elif self.status.state == deluge.common.LT_TORRENT_STATE["Checking"]:
|
self.state = "Seeding"
|
||||||
self.set_state("Checking")
|
|
||||||
else:
|
else:
|
||||||
self.set_state("Paused")
|
self.state = "Downloading"
|
||||||
|
|
||||||
# Various torrent options
|
# Various torrent options
|
||||||
self.max_connections = -1
|
self.max_connections = -1
|
||||||
|
@ -110,6 +108,8 @@ class Torrent:
|
||||||
# Set the default file priorities to normal
|
# Set the default file priorities to normal
|
||||||
self.file_priorities = [1]* len(self.files)
|
self.file_priorities = [1]* len(self.files)
|
||||||
|
|
||||||
|
log.debug("Torrent object created.")
|
||||||
|
|
||||||
def set_tracker_status(self, status):
|
def set_tracker_status(self, status):
|
||||||
"""Sets the tracker status"""
|
"""Sets the tracker status"""
|
||||||
self.tracker_status = status
|
self.tracker_status = status
|
||||||
|
|
|
@ -108,7 +108,7 @@ class TorrentManager(component.Component):
|
||||||
# Create the torrents dict { torrent_id: Torrent }
|
# Create the torrents dict { torrent_id: Torrent }
|
||||||
self.torrents = {}
|
self.torrents = {}
|
||||||
|
|
||||||
# List of torrents to note set state 'Paused' on lt alert
|
# List of torrents to not set state 'Paused' on lt alert
|
||||||
self.not_state_paused = []
|
self.not_state_paused = []
|
||||||
|
|
||||||
# Register set functions
|
# Register set functions
|
||||||
|
@ -252,7 +252,9 @@ class TorrentManager(component.Component):
|
||||||
except RuntimeError, e:
|
except RuntimeError, e:
|
||||||
log.warning("Error adding torrent: %s", e)
|
log.warning("Error adding torrent: %s", e)
|
||||||
|
|
||||||
|
log.debug("after torrent add")
|
||||||
if not handle or not handle.is_valid():
|
if not handle or not handle.is_valid():
|
||||||
|
log.debug("torrent handle is invalid!")
|
||||||
# The torrent was not added to the session
|
# The torrent was not added to the session
|
||||||
component.resume("AlertManager")
|
component.resume("AlertManager")
|
||||||
return None
|
return None
|
||||||
|
@ -260,11 +262,11 @@ class TorrentManager(component.Component):
|
||||||
# Create a Torrent object
|
# Create a Torrent object
|
||||||
torrent = Torrent(filename, handle, options["compact_allocation"],
|
torrent = Torrent(filename, handle, options["compact_allocation"],
|
||||||
options["download_location"], total_uploaded, trackers)
|
options["download_location"], total_uploaded, trackers)
|
||||||
|
log.debug("torrent: %s", torrent)
|
||||||
component.resume("AlertManager")
|
|
||||||
|
|
||||||
# Add the torrent object to the dictionary
|
# Add the torrent object to the dictionary
|
||||||
self.torrents[torrent.torrent_id] = torrent
|
self.torrents[torrent.torrent_id] = torrent
|
||||||
|
log.debug("self.torrents: %s", self.torrents)
|
||||||
|
component.resume("AlertManager")
|
||||||
|
|
||||||
# Add the torrent to the queue
|
# Add the torrent to the queue
|
||||||
if queue == -1 and self.config["queue_new_to_top"]:
|
if queue == -1 and self.config["queue_new_to_top"]:
|
||||||
|
@ -292,8 +294,10 @@ class TorrentManager(component.Component):
|
||||||
torrent.state = "Queued"
|
torrent.state = "Queued"
|
||||||
elif state == "Paused":
|
elif state == "Paused":
|
||||||
torrent.state = "Paused"
|
torrent.state = "Paused"
|
||||||
elif state == None and not options["add_paused"]:
|
if state == None and not options["add_paused"]:
|
||||||
torrent.handle.resume()
|
torrent.handle.resume()
|
||||||
|
if state == None and options["add_paused"]:
|
||||||
|
torrent.state = "Paused"
|
||||||
|
|
||||||
# Save the torrent file
|
# Save the torrent file
|
||||||
torrent.save_torrent_file(filedump)
|
torrent.save_torrent_file(filedump)
|
||||||
|
@ -617,6 +621,7 @@ 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("self.torrents: %s", self.torrents)
|
||||||
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_seed():
|
||||||
self.torrents[torrent_id].set_state("Seeding")
|
self.torrents[torrent_id].set_state("Seeding")
|
||||||
|
|
Loading…
Reference in New Issue