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