Save and load total_uploaded from torrent state.
This commit is contained in:
parent
54b1665c50
commit
33fd818933
|
@ -38,7 +38,7 @@ import deluge.common
|
|||
class Torrent:
|
||||
"""Torrent holds information about torrents added to the libtorrent session.
|
||||
"""
|
||||
def __init__(self, filename, handle, compact, save_path):
|
||||
def __init__(self, filename, handle, compact, save_path, total_uploaded=0):
|
||||
# Set the filename
|
||||
self.filename = filename
|
||||
# Set the libtorrent handle
|
||||
|
@ -46,7 +46,7 @@ class Torrent:
|
|||
# Set the torrent_id for this torrent
|
||||
self.torrent_id = str(handle.info_hash())
|
||||
# This is for saving the total uploaded between sessions
|
||||
self.total_uploaded = 0
|
||||
self.total_uploaded = total_uploaded
|
||||
# Set the allocation mode
|
||||
self.compact = compact
|
||||
# Where the torrent is being saved to
|
||||
|
@ -62,7 +62,7 @@ class Torrent:
|
|||
"""Returns the state of this torrent for saving to the session state"""
|
||||
status = self.handle.status()
|
||||
return (self.torrent_id, self.filename, self.compact, status.paused,
|
||||
self.save_path)
|
||||
self.save_path, self.total_uploaded)
|
||||
|
||||
def get_eta(self):
|
||||
"""Returns the ETA in seconds for this torrent"""
|
||||
|
|
|
@ -47,12 +47,14 @@ from deluge.core.torrent import Torrent
|
|||
from deluge.log import LOG as log
|
||||
|
||||
class TorrentState:
|
||||
def __init__(self, torrent_id, filename, compact, paused, save_path):
|
||||
def __init__(self, torrent_id, filename, compact, paused, save_path,
|
||||
total_uploaded):
|
||||
self.torrent_id = torrent_id
|
||||
self.filename = filename
|
||||
self.compact = compact
|
||||
self.paused = paused
|
||||
self.save_path = save_path
|
||||
self.total_uploaded = total_uploaded
|
||||
|
||||
class TorrentManagerState:
|
||||
def __init__(self):
|
||||
|
@ -119,7 +121,7 @@ class TorrentManager:
|
|||
return self.torrents.keys()
|
||||
|
||||
def add(self, filename, filedump=None, compact=None, paused=False,
|
||||
save_path=None):
|
||||
save_path=None, total_uploaded=0):
|
||||
"""Add a torrent to the manager and returns it's torrent_id"""
|
||||
log.info("Adding torrent: %s", filename)
|
||||
|
||||
|
@ -186,7 +188,8 @@ class TorrentManager:
|
|||
|
||||
# Create a Torrent object
|
||||
torrent = Torrent(filename, handle, compact,
|
||||
save_path)
|
||||
save_path, total_uploaded)
|
||||
|
||||
# Add the torrent object to the dictionary
|
||||
self.torrents[torrent.torrent_id] = torrent
|
||||
|
||||
|
@ -310,7 +313,8 @@ class TorrentManager:
|
|||
# Try to add the torrents in the state to the session
|
||||
for torrent_state in state.torrents:
|
||||
self.add(torrent_state.filename, compact=torrent_state.compact,
|
||||
paused=torrent_state.paused, save_path=torrent_state.save_path)
|
||||
paused=torrent_state.paused, save_path=torrent_state.save_path,
|
||||
total_uploaded=torrent_state.total_uploaded)
|
||||
|
||||
def save_state(self):
|
||||
"""Save the state of the TorrentManager to the torrents.state file"""
|
||||
|
|
Loading…
Reference in New Issue