mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-12 12:34:43 +00:00
Store allocation type in the torrent state file and add the ability to
add a torrent with a different allocation type then what is set in the config.
This commit is contained in:
parent
4a2bb465f0
commit
f764448cad
@ -114,7 +114,7 @@ class Core(dbus.service.Object):
|
||||
listen_ports[1])
|
||||
|
||||
# Load metadata extension
|
||||
self.session.add_extension(lt.create_metadata_plugin)
|
||||
#self.session.add_extension(lt.create_metadata_plugin)
|
||||
|
||||
# Load utorrent peer-exchange
|
||||
if self.config["utpex"]:
|
||||
|
@ -36,7 +36,7 @@
|
||||
class Torrent:
|
||||
"""Torrent holds information about torrents added to the libtorrent session.
|
||||
"""
|
||||
def __init__(self, filename, handle):
|
||||
def __init__(self, filename, handle, compact):
|
||||
# Set the filename
|
||||
self.filename = filename
|
||||
# Set the libtorrent handle
|
||||
@ -45,10 +45,12 @@ class Torrent:
|
||||
self.torrent_id = str(handle.info_hash())
|
||||
# This is for saving the total uploaded between sessions
|
||||
self.total_uploaded = 0
|
||||
# Set the allocation mode
|
||||
self.compact = compact
|
||||
|
||||
def get_state(self):
|
||||
"""Returns the state of this torrent for saving to the session state"""
|
||||
return (self.torrent_id, self.filename)
|
||||
return (self.torrent_id, self.filename, self.compact)
|
||||
|
||||
def get_eta(self):
|
||||
"""Returns the ETA in seconds for this torrent"""
|
||||
|
@ -45,9 +45,10 @@ from deluge.core.torrent import Torrent
|
||||
from deluge.log import LOG as log
|
||||
|
||||
class TorrentState:
|
||||
def __init__(self, torrent_id, filename):
|
||||
def __init__(self, torrent_id, filename, compact):
|
||||
self.torrent_id = torrent_id
|
||||
self.filename = filename
|
||||
self.compact = compact
|
||||
|
||||
class TorrentManagerState:
|
||||
def __init__(self):
|
||||
@ -80,7 +81,7 @@ class TorrentManager:
|
||||
"""Returns a list of torrent_ids"""
|
||||
return self.torrents.keys()
|
||||
|
||||
def add(self, filename, filedump=None):
|
||||
def add(self, filename, filedump=None, compact=None):
|
||||
"""Add a torrent to the manager and returns it's torrent_id"""
|
||||
log.info("Adding torrent: %s", filename)
|
||||
# Get the core config
|
||||
@ -106,11 +107,16 @@ class TorrentManager:
|
||||
torrent_filedump = lt.bdecode(filedump)
|
||||
handle = None
|
||||
|
||||
# Make sure we are adding it with the correct allocation method.
|
||||
if compact is None:
|
||||
compact = config["compact_allocation"]
|
||||
print "compact: ", compact
|
||||
|
||||
try:
|
||||
handle = self.session.add_torrent(
|
||||
lt.torrent_info(torrent_filedump),
|
||||
config["download_location"],
|
||||
config["compact_allocation"])
|
||||
compact)
|
||||
except RuntimeError:
|
||||
log.warning("Error adding torrent")
|
||||
|
||||
@ -140,7 +146,7 @@ class TorrentManager:
|
||||
|
||||
log.debug("Torrent %s added.", handle.info_hash())
|
||||
# Create a Torrent object
|
||||
torrent = Torrent(filename, handle)
|
||||
torrent = Torrent(filename, handle, compact)
|
||||
# Add the torrent object to the dictionary
|
||||
self.torrents[torrent.torrent_id] = torrent
|
||||
# Save the session state
|
||||
@ -197,7 +203,7 @@ class TorrentManager:
|
||||
|
||||
# Try to add the torrents in the state to the session
|
||||
for torrent_state in state.torrents:
|
||||
self.add(torrent_state.filename)
|
||||
self.add(torrent_state.filename, compact=torrent_state.compact)
|
||||
|
||||
def save_state(self):
|
||||
"""Save the state of the TorrentManager to the torrents.state file"""
|
||||
|
Loading…
x
Reference in New Issue
Block a user