Move owner to torrent options

This commit is contained in:
Calum Lind 2014-02-14 13:27:08 +00:00
parent a9ed6fe46a
commit 0aed074796
2 changed files with 17 additions and 21 deletions

View File

@ -48,6 +48,7 @@ import deluge.component as component
from deluge.configmanager import ConfigManager, get_config_dir
from deluge.event import TorrentStateChangedEvent, TorrentFolderRenamedEvent
from deluge.common import decode_string
from deluge.core.authmanager import AUTH_LEVEL_ADMIN
TORRENT_STATE = deluge.common.TORRENT_STATE
@ -137,12 +138,13 @@ class TorrentOptions(dict):
self[opt_k] = config[conf_k]
self["file_priorities"] = []
self["mapped_files"] = {}
self["owner"] = None
class Torrent(object):
"""Torrent holds information about torrents added to the libtorrent session.
"""
def __init__(self, handle, options, state=None, filename=None, magnet=None, owner=None):
def __init__(self, handle, options, state=None, filename=None, magnet=None):
# Set the torrent_id for this torrent
self.torrent_id = str(handle.info_hash())
@ -226,12 +228,6 @@ class Torrent(object):
# This gets updated when get_tracker_host is called
self.tracker_host = None
# Keep track of the owner
if state:
self.owner = state.owner
else:
self.owner = owner
# Keep track if we're forcing a recheck of the torrent so that we can
# re-pause it after its done if necessary
self.forcing_recheck = False
@ -432,6 +428,10 @@ class Torrent(object):
else:
raise ValueError("Torrent priority, %s, is invalid, should be [0..255]", priority)
def set_owner(self, account):
if self.rpcserver.get_session_auth_level() == AUTH_LEVEL_ADMIN:
self.options["owner"] = account
### End Options methods ###
def set_trackers(self, trackers):
@ -474,9 +474,6 @@ class Torrent(object):
"""Sets the tracker status"""
self.tracker_status = self.get_tracker_host() + ": " + status
def set_owner(self, account):
self.owner = account
def update_state(self):
"""Updates the state based on what libtorrent's state for the torrent is"""
# Set the initial state based on the lt state
@ -761,7 +758,7 @@ class Torrent(object):
"next_announce": lambda: self.status.next_announce.seconds,
"num_peers": lambda: self.status.num_peers - self.status.num_seeds,
"num_seeds": lambda: self.status.num_seeds,
"owner": lambda: self.owner,
"owner": lambda: self.options["owner"],
"paused": lambda: self.status.paused,
"prioritize_first_last": lambda: self.options["prioritize_first_last_pieces"],
"sequential_download": lambda: self.options["sequential_download"],

View File

@ -97,7 +97,6 @@ class TorrentState:
self.queue = queue
self.is_finished = is_finished
self.magnet = magnet
self.owner = owner
# Options
self.compact = compact
@ -119,7 +118,7 @@ class TorrentState:
self.shared = shared
self.super_seeding = super_seeding
self.priority = priority
self.owner = owner
class TorrentManagerState:
def __init__(self):
@ -317,7 +316,7 @@ class TorrentManager(component.Component):
return torrent_info
def add(self, torrent_info=None, state=None, options=None, save_state=True,
filedump=None, filename=None, magnet=None, resume_data=None, seed_mode=False, owner=None):
filedump=None, filename=None, magnet=None, resume_data=None, seed_mode=False):
"""Add a torrent to the manager and returns it's torrent_id"""
if torrent_info is None and state is None and filedump is None and magnet is None:
log.debug("You must specify a valid torrent_info, torrent state or magnet.")
@ -358,7 +357,7 @@ class TorrentManager(component.Component):
options["shared"] = state.shared
options["super_seeding"] = state.super_seeding
options["priority"] = state.priority
owner = state.owner
options["owner"] = state.owner
torrent_info = self.get_torrent_info_from_file(
os.path.join(self.state_dir, state.torrent_id + ".torrent"))
@ -430,11 +429,11 @@ class TorrentManager(component.Component):
if log.isEnabledFor(logging.DEBUG):
log.debug("options: %s", options)
if not owner:
owner = component.get("RPCServer").get_session_user()
account_exists = component.get("AuthManager").has_account(owner)
if not options["owner"]:
options["owner"] = component.get("RPCServer").get_session_user()
account_exists = component.get("AuthManager").has_account(options["owner"])
if not account_exists:
owner = "localclient"
options["owner"] = "localclient"
# Set the right storage_mode
if options["compact_allocation"]:
@ -481,7 +480,7 @@ class TorrentManager(component.Component):
# Set auto_managed to False because the torrent is paused
handle.auto_managed(False)
# Create a Torrent object
torrent = Torrent(handle, options, state, filename, magnet, owner)
torrent = Torrent(handle, options, state, filename, magnet)
# Add the torrent object to the dictionary
self.torrents[torrent.torrent_id] = torrent
@ -696,7 +695,7 @@ class TorrentManager(component.Component):
torrent.options["move_completed"],
torrent.options["move_completed_path"],
torrent.magnet,
torrent.owner,
torrent.options["owner"],
torrent.options["shared"],
torrent.options["super_seeding"],
torrent.options["priority"]