Fix Queue plugin loading when state file is wrong.

This commit is contained in:
Andrew Resch 2007-12-11 01:35:36 +00:00
commit f3cdfa8351
3 changed files with 25 additions and 9 deletions

View file

@ -112,4 +112,7 @@ class PluginManager(deluge.pluginmanagerbase.PluginManagerBase,
log.debug("run_post_torrent_remove") log.debug("run_post_torrent_remove")
for function in self.hooks["post_torrent_remove"]: for function in self.hooks["post_torrent_remove"]:
function(torrent_id) function(torrent_id)
def get_torrent_list(self):
"""Returns a list of torrent_id's in the current session."""
return component.get("TorrentManager").get_torrent_list()

View file

@ -37,8 +37,10 @@ from deluge.plugins.corepluginbase import CorePluginBase
class Core(CorePluginBase): class Core(CorePluginBase):
def enable(self): def enable(self):
# Instantiate the TorrentQueue object # Get a list of torrent_ids in the session
self.queue = TorrentQueue() # We give this to the TorrentQueue to compare with the saved state
# and create the queuing order.
self.queue = TorrentQueue(self.plugin.get_torrent_list())
# Register core hooks # Register core hooks
self.plugin.register_hook("post_torrent_add", self._post_torrent_add) self.plugin.register_hook("post_torrent_add", self._post_torrent_add)

View file

@ -37,10 +37,19 @@ import deluge.common
from deluge.log import LOG as log from deluge.log import LOG as log
class TorrentQueue: class TorrentQueue:
def __init__(self): def __init__(self, torrent_list):
self.queue = []
# Try to load the queue state from file # Try to load the queue state from file
self.load_state() self.queue = self.load_state()
# First remove any torrent_ids in self.queue that are not in the current
# session list.
for torrent_id in self.queue:
if torrent_id not in torrent_list:
self.queue.remove(torrent_id)
# Next we append any torrents in the session list to self.queue
for torrent_id in torrent_list:
if torrent_id not in self.queue:
self.queue.append(torrent_id)
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"""
@ -57,9 +66,11 @@ class TorrentQueue:
"rb") "rb")
state = pickle.load(state_file) state = pickle.load(state_file)
state_file.close() state_file.close()
self.queue = state return state
except IOError: except IOError, e:
log.warning("Unable to load queue state file.") log.warning("Unable to load queue state file: %s", e)
return []
def save_state(self): def save_state(self):
"""Save the queue state""" """Save the queue state"""