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