Save torrent state every 5 minutes.

This commit is contained in:
Andrew Resch 2007-10-03 02:57:05 +00:00
commit 170c3810b3
2 changed files with 8 additions and 2 deletions

2
TODO
View file

@ -14,6 +14,4 @@
to add menuitems to the torrentmenu in an easy way. to add menuitems to the torrentmenu in an easy way.
* Restart daemon function * Restart daemon function
* Sync the details pane to current trunk * Sync the details pane to current trunk
* Automatically save torrent state every ~5 minutes, much like how
configmanager does it.
* Docstrings! * Docstrings!

View file

@ -37,6 +37,8 @@ import pickle
import os.path import os.path
import os import os
import gobject
import deluge.libtorrent as lt import deluge.libtorrent as lt
import deluge.common import deluge.common
@ -75,6 +77,9 @@ class TorrentManager:
self.torrents = {} self.torrents = {}
# Try to load the state from file # Try to load the state from file
self.load_state() self.load_state()
# Save the state every 5 minutes
self.save_state_timer = gobject.timeout_add(300000, self.save_state)
# Register set functions # Register set functions
self.config.register_set_function("max_connections_per_torrent", self.config.register_set_function("max_connections_per_torrent",
@ -317,6 +322,9 @@ class TorrentManager:
state_file.close() state_file.close()
except IOError: except IOError:
log.warning("Unable to save state file.") log.warning("Unable to save state file.")
# We return True so that the timer thread will continue
return True
def delete_fastresume(self, torrent_id): def delete_fastresume(self, torrent_id):
"""Deletes the .fastresume file""" """Deletes the .fastresume file"""