Change torrent.OPTIONS to a new TorrentOptions object

This commit is contained in:
Andrew Resch 2008-09-17 00:26:14 +00:00
commit 58bca167b3
2 changed files with 65 additions and 24 deletions

View file

@ -41,28 +41,68 @@ import deluge.common
import deluge.component as component import deluge.component as component
from deluge.configmanager import ConfigManager from deluge.configmanager import ConfigManager
from deluge.log import LOG as log from deluge.log import LOG as log
from deluge.core.preferencesmanager import DEFAULT_PREFS
import deluge.xmlrpclib import deluge.xmlrpclib
TORRENT_STATE = deluge.common.TORRENT_STATE TORRENT_STATE = deluge.common.TORRENT_STATE
OPTIONS = { class TorrentOptions(dict):
"max_download_speed": DEFAULT_PREFS["max_download_speed_per_torrent"], def __init__(self):
"max_upload_speed": DEFAULT_PREFS["max_upload_speed_per_torrent"], self.config = ConfigManager("core.conf")
"max_connections": DEFAULT_PREFS["max_connections_per_torrent"], self.default_keys = {
"max_upload_slots": DEFAULT_PREFS["max_upload_slots_per_torrent"], "max_download_speed": "max_download_speed_per_torrent",
"prioritize_first_last_pieces": DEFAULT_PREFS["prioritize_first_last_pieces"], "max_upload_speed": "max_upload_speed_per_torrent",
"auto_managed": DEFAULT_PREFS["auto_managed"], "max_connections": "max_connections_per_torrent",
"stop_at_ratio": DEFAULT_PREFS["stop_seed_at_ratio"], "max_upload_slots": "max_upload_slots_per_torrent",
"stop_ratio": DEFAULT_PREFS["stop_seed_ratio"], "prioritize_first_last_pieces": "prioritize_first_last_pieces",
"remove_at_ratio": DEFAULT_PREFS["remove_seed_at_ratio"], "auto_managed": "auto_managed",
"move_completed": DEFAULT_PREFS["move_completed"], "stop_at_ratio": "stop_seed_at_ratio",
"move_completed_path": DEFAULT_PREFS["move_completed_path"], "stop_ratio": "stop_seed_ratio",
"file_priorities": [], "remove_at_ratio": "remove_seed_at_ratio",
"compact_allocation": DEFAULT_PREFS["compact_allocation"], "move_completed": "move_completed",
"download_location": DEFAULT_PREFS["download_location"], "move_completed_path": "move_completed_path",
"add_paused": DEFAULT_PREFS["add_paused"] "file_priorities": [],
} "compact_allocation": "compact_allocation",
"download_location": "download_location",
"add_paused": "add_paused"
}
def items(self):
i = super(TorrentOptions, self).items()
for k in self.default_keys:
if k not in super(TorrentOptions, self).keys():
i.append((k, self.__getitem__(k)))
return i
def keys(self):
k = super(TorrentOptions, self).keys()
for key in self.default_keys.keys():
if key not in k:
k.append(key)
return k
def iteritems(self):
return self.items().itermitems()
def has_key(self, key):
if super(TorrentOptions, self).has_key(key):
return True
elif self.default_keys.has_key(key):
return True
return False
def __setitem__(self, key, value):
super(TorrentOptions, self).__setitem__(key, value)
def __getitem__(self, key):
if super(TorrentOptions, self).has_key(key):
return super(TorrentOptions, self).__getitem__(key)
else:
if self.default_keys[key]:
return self.config[self.default_keys[key]]
else:
return self.default_keys[key]
class Torrent: class Torrent:
"""Torrent holds information about torrents added to the libtorrent session. """Torrent holds information about torrents added to the libtorrent session.
@ -104,7 +144,7 @@ class Torrent:
self.total_uploaded = 0 self.total_uploaded = 0
# Set the default options # Set the default options
self.options = OPTIONS.copy() self.options = TorrentOptions()
self.options.update(options) self.options.update(options)
# We need to keep track if the torrent is finished in the state to prevent # We need to keep track if the torrent is finished in the state to prevent
@ -171,6 +211,7 @@ class Torrent:
def get_options(self): def get_options(self):
return self.options return self.options
def set_max_connections(self, max_connections): def set_max_connections(self, max_connections):
self.options["max_connections"] = int(max_connections) self.options["max_connections"] = int(max_connections)
self.handle.set_max_connections(max_connections) self.handle.set_max_connections(max_connections)

View file

@ -46,7 +46,7 @@ import deluge.common
import deluge.component as component import deluge.component as component
from deluge.configmanager import ConfigManager from deluge.configmanager import ConfigManager
from deluge.core.torrent import Torrent from deluge.core.torrent import Torrent
from deluge.core.torrent import OPTIONS from deluge.core.torrent import TorrentOptions
import deluge.core.oldstateupgrader import deluge.core.oldstateupgrader
from deluge.log import LOG as log from deluge.log import LOG as log
@ -271,7 +271,7 @@ class TorrentManager(component.Component):
# from the state object. # from the state object.
# Populate the options dict from state # Populate the options dict from state
options = OPTIONS.copy() options = TorrentOptions()
options["max_connections"] = state.max_connections options["max_connections"] = state.max_connections
options["max_upload_slots"] = state.max_upload_slots options["max_upload_slots"] = state.max_upload_slots
options["max_upload_speed"] = state.max_upload_speed options["max_upload_speed"] = state.max_upload_speed
@ -295,9 +295,9 @@ class TorrentManager(component.Component):
# We have a torrent_info object so we're not loading from state. # We have a torrent_info object so we're not loading from state.
# Check if options is None and load defaults # Check if options is None and load defaults
if options == None: if options == None:
options = OPTIONS.copy() options = TorrentOptions()
else: else:
o = OPTIONS.copy() o = TorrentOptions()
o.update(options) o.update(options)
options = o options = o