From f764448cad0ecd47c9fbabe13a8cd1502ce6f87d Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Mon, 17 Sep 2007 04:19:59 +0000 Subject: [PATCH] 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. --- deluge/core/core.py | 2 +- deluge/core/torrent.py | 6 ++++-- deluge/core/torrentmanager.py | 16 +++++++++++----- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/deluge/core/core.py b/deluge/core/core.py index 38de95e49..1630d46ac 100644 --- a/deluge/core/core.py +++ b/deluge/core/core.py @@ -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"]: diff --git a/deluge/core/torrent.py b/deluge/core/torrent.py index aa7fc497c..0058c1285 100644 --- a/deluge/core/torrent.py +++ b/deluge/core/torrent.py @@ -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""" diff --git a/deluge/core/torrentmanager.py b/deluge/core/torrentmanager.py index 0b0ca09bf..f9e4166d0 100644 --- a/deluge/core/torrentmanager.py +++ b/deluge/core/torrentmanager.py @@ -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"""