Remove 'state_location' and 'config_location' preferences and all references from the code. We should use configmanager.get_config_dir() instead.
This commit is contained in:
parent
7749f99828
commit
0be6d83d92
|
@ -315,6 +315,8 @@ class Core(component.Component):
|
||||||
Gets the session status values for 'keys', these keys are taking
|
Gets the session status values for 'keys', these keys are taking
|
||||||
from libtorrent's session status.
|
from libtorrent's session status.
|
||||||
|
|
||||||
|
See: http://www.rasterbar.com/products/libtorrent/manual.html#status
|
||||||
|
|
||||||
:param keys: the keys for which we want values
|
:param keys: the keys for which we want values
|
||||||
:type keys: list
|
:type keys: list
|
||||||
:returns: a dictionary of {key: value, ...}
|
:returns: a dictionary of {key: value, ...}
|
||||||
|
@ -658,7 +660,7 @@ class Core(component.Component):
|
||||||
the client side. 'plugin_data' is a xmlrpc.Binary object of the file data,
|
the client side. 'plugin_data' is a xmlrpc.Binary object of the file data,
|
||||||
ie, plugin_file.read()"""
|
ie, plugin_file.read()"""
|
||||||
|
|
||||||
f = open(os.path.join(self.config["config_location"], "plugins", filename), "wb")
|
f = open(os.path.join(deluge.configmanager.get_config_dir(), "plugins", filename), "wb")
|
||||||
f.write(plugin_data.data)
|
f.write(plugin_data.data)
|
||||||
f.close()
|
f.close()
|
||||||
component.get("CorePluginManager").scan_for_plugins()
|
component.get("CorePluginManager").scan_for_plugins()
|
||||||
|
|
|
@ -42,7 +42,7 @@ import shutil
|
||||||
|
|
||||||
from deluge._libtorrent import lt
|
from deluge._libtorrent import lt
|
||||||
|
|
||||||
from deluge.configmanager import ConfigManager
|
from deluge.configmanager import ConfigManager, get_config_dir
|
||||||
import deluge.core.torrentmanager
|
import deluge.core.torrentmanager
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
|
|
||||||
|
@ -69,8 +69,8 @@ class PickleUpgrader(pickle.Unpickler):
|
||||||
class OldStateUpgrader:
|
class OldStateUpgrader:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.config = ConfigManager("core.conf")
|
self.config = ConfigManager("core.conf")
|
||||||
self.state05_location = os.path.join(self.config["config_location"], "persistent.state")
|
self.state05_location = os.path.join(get_config_dir(), "persistent.state")
|
||||||
self.state10_location = os.path.join(self.config["state_location"], "torrents.state")
|
self.state10_location = os.path.join(get_config_dir(), "state", "torrents.state")
|
||||||
if os.path.exists(self.state05_location) and not os.path.exists(self.state10_location):
|
if os.path.exists(self.state05_location) and not os.path.exists(self.state10_location):
|
||||||
# If the 0.5 state file exists and the 1.0 doesn't, then let's upgrade it
|
# If the 0.5 state file exists and the 1.0 doesn't, then let's upgrade it
|
||||||
self.upgrade05()
|
self.upgrade05()
|
||||||
|
@ -89,7 +89,7 @@ class OldStateUpgrader:
|
||||||
|
|
||||||
new_state = deluge.core.torrentmanager.TorrentManagerState()
|
new_state = deluge.core.torrentmanager.TorrentManagerState()
|
||||||
for ti, uid in state.torrents.items():
|
for ti, uid in state.torrents.items():
|
||||||
torrent_path = os.path.join(self.config["config_location"], "torrentfiles", ti.filename)
|
torrent_path = os.path.join(get_config_dir(), "torrentfiles", ti.filename)
|
||||||
try:
|
try:
|
||||||
torrent_info = None
|
torrent_info = None
|
||||||
log.debug("Attempting to create torrent_info from %s", torrent_path)
|
log.debug("Attempting to create torrent_info from %s", torrent_path)
|
||||||
|
@ -101,7 +101,7 @@ class OldStateUpgrader:
|
||||||
|
|
||||||
# Copy the torrent file to the new location
|
# Copy the torrent file to the new location
|
||||||
import shutil
|
import shutil
|
||||||
shutil.copyfile(torrent_path, os.path.join(self.config["state_location"], str(torrent_info.info_hash()) + ".torrent"))
|
shutil.copyfile(torrent_path, os.path.join(get_config_dir(), "state", str(torrent_info.info_hash()) + ".torrent"))
|
||||||
|
|
||||||
# Set the file prioritiy property if not already there
|
# Set the file prioritiy property if not already there
|
||||||
if not hasattr(ti, "priorities"):
|
if not hasattr(ti, "priorities"):
|
||||||
|
@ -127,7 +127,7 @@ class OldStateUpgrader:
|
||||||
try:
|
try:
|
||||||
log.debug("Saving torrent state file.")
|
log.debug("Saving torrent state file.")
|
||||||
state_file = open(
|
state_file = open(
|
||||||
os.path.join(self.config["state_location"], "torrents.state"), "wb")
|
os.path.join(get_config_dir(), "state", "torrents.state"), "wb")
|
||||||
cPickle.dump(new_state, state_file)
|
cPickle.dump(new_state, state_file)
|
||||||
state_file.close()
|
state_file.close()
|
||||||
except IOError, e:
|
except IOError, e:
|
||||||
|
|
|
@ -49,7 +49,6 @@ import deluge.component as component
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
|
|
||||||
DEFAULT_PREFS = {
|
DEFAULT_PREFS = {
|
||||||
"config_location": deluge.configmanager.get_config_dir(),
|
|
||||||
"send_info": False,
|
"send_info": False,
|
||||||
"info_sent": 0.0,
|
"info_sent": 0.0,
|
||||||
"daemon_port": 58846,
|
"daemon_port": 58846,
|
||||||
|
@ -61,7 +60,6 @@ DEFAULT_PREFS = {
|
||||||
"copy_torrent_file": False,
|
"copy_torrent_file": False,
|
||||||
"torrentfiles_location": deluge.common.get_default_download_dir(),
|
"torrentfiles_location": deluge.common.get_default_download_dir(),
|
||||||
"plugins_location": os.path.join(deluge.configmanager.get_config_dir(), "plugins"),
|
"plugins_location": os.path.join(deluge.configmanager.get_config_dir(), "plugins"),
|
||||||
"state_location": os.path.join(deluge.configmanager.get_config_dir(), "state"),
|
|
||||||
"prioritize_first_last_pieces": False,
|
"prioritize_first_last_pieces": False,
|
||||||
"random_port": True,
|
"random_port": True,
|
||||||
"dht": True,
|
"dht": True,
|
||||||
|
@ -158,8 +156,6 @@ class PreferencesManager(component.Component):
|
||||||
# Register set functions in the Config
|
# Register set functions in the Config
|
||||||
self.config.register_set_function("torrentfiles_location",
|
self.config.register_set_function("torrentfiles_location",
|
||||||
self._on_set_torrentfiles_location)
|
self._on_set_torrentfiles_location)
|
||||||
self.config.register_set_function("state_location",
|
|
||||||
self._on_set_state_location)
|
|
||||||
self.config.register_set_function("listen_ports",
|
self.config.register_set_function("listen_ports",
|
||||||
self._on_set_listen_ports)
|
self._on_set_listen_ports)
|
||||||
self.config.register_set_function("listen_interface",
|
self.config.register_set_function("listen_interface",
|
||||||
|
@ -246,13 +242,6 @@ class PreferencesManager(component.Component):
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
log.debug("Unable to make directory: %s", e)
|
log.debug("Unable to make directory: %s", e)
|
||||||
|
|
||||||
def _on_set_state_location(self, key, value):
|
|
||||||
if not os.access(value, os.F_OK):
|
|
||||||
try:
|
|
||||||
os.makedirs(value)
|
|
||||||
except Exception, e:
|
|
||||||
log.debug("Unable to make directory: %s", e)
|
|
||||||
|
|
||||||
def _on_set_listen_ports(self, key, value):
|
def _on_set_listen_ports(self, key, value):
|
||||||
# Only set the listen ports if random_port is not true
|
# Only set the listen ports if random_port is not true
|
||||||
if self.config["random_port"] is not True:
|
if self.config["random_port"] is not True:
|
||||||
|
|
|
@ -42,7 +42,7 @@ from deluge._libtorrent import lt
|
||||||
|
|
||||||
import deluge.common
|
import deluge.common
|
||||||
import deluge.component as component
|
import deluge.component as component
|
||||||
from deluge.configmanager import ConfigManager
|
from deluge.configmanager import ConfigManager, get_config_dir
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
from deluge.event import *
|
from deluge.event import *
|
||||||
|
|
||||||
|
@ -759,7 +759,7 @@ class Torrent:
|
||||||
"""Writes the .fastresume file for the torrent"""
|
"""Writes the .fastresume file for the torrent"""
|
||||||
resume_data = lt.bencode(resume_data)
|
resume_data = lt.bencode(resume_data)
|
||||||
path = "%s/%s.fastresume" % (
|
path = "%s/%s.fastresume" % (
|
||||||
self.config["state_location"],
|
os.path.join(get_config_dir(), "state"),
|
||||||
self.torrent_id)
|
self.torrent_id)
|
||||||
try:
|
try:
|
||||||
self.delete_fastresume()
|
self.delete_fastresume()
|
||||||
|
@ -777,7 +777,7 @@ class Torrent:
|
||||||
def delete_fastresume(self):
|
def delete_fastresume(self):
|
||||||
"""Deletes the .fastresume file"""
|
"""Deletes the .fastresume file"""
|
||||||
path = "%s/%s.fastresume" % (
|
path = "%s/%s.fastresume" % (
|
||||||
self.config["state_location"],
|
os.path.join(get_config_dir(), "state"),
|
||||||
self.torrent_id)
|
self.torrent_id)
|
||||||
log.debug("Deleting fastresume file: %s", path)
|
log.debug("Deleting fastresume file: %s", path)
|
||||||
try:
|
try:
|
||||||
|
@ -788,7 +788,7 @@ class Torrent:
|
||||||
def write_torrentfile(self):
|
def write_torrentfile(self):
|
||||||
"""Writes the torrent file"""
|
"""Writes the torrent file"""
|
||||||
path = "%s/%s.torrent" % (
|
path = "%s/%s.torrent" % (
|
||||||
self.config["state_location"],
|
os.path.join(get_config_dir(), "state"),
|
||||||
self.torrent_id)
|
self.torrent_id)
|
||||||
log.debug("Writing torrent file: %s", path)
|
log.debug("Writing torrent file: %s", path)
|
||||||
try:
|
try:
|
||||||
|
@ -804,7 +804,7 @@ class Torrent:
|
||||||
def delete_torrentfile(self):
|
def delete_torrentfile(self):
|
||||||
"""Deletes the .torrent file in the state"""
|
"""Deletes the .torrent file in the state"""
|
||||||
path = "%s/%s.torrent" % (
|
path = "%s/%s.torrent" % (
|
||||||
self.config["state_location"],
|
os.path.join(get_config_dir(), "state"),
|
||||||
self.torrent_id)
|
self.torrent_id)
|
||||||
log.debug("Deleting torrent file: %s", path)
|
log.debug("Deleting torrent file: %s", path)
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -52,7 +52,7 @@ from deluge.event import *
|
||||||
from deluge.error import *
|
from deluge.error import *
|
||||||
import deluge.common
|
import deluge.common
|
||||||
import deluge.component as component
|
import deluge.component as component
|
||||||
from deluge.configmanager import ConfigManager
|
from deluge.configmanager import ConfigManager, get_config_dir
|
||||||
from deluge.core.torrent import Torrent
|
from deluge.core.torrent import Torrent
|
||||||
from deluge.core.torrent import TorrentOptions
|
from deluge.core.torrent import TorrentOptions
|
||||||
import deluge.core.oldstateupgrader
|
import deluge.core.oldstateupgrader
|
||||||
|
@ -269,7 +269,7 @@ class TorrentManager(component.Component):
|
||||||
try:
|
try:
|
||||||
_file = open(
|
_file = open(
|
||||||
os.path.join(
|
os.path.join(
|
||||||
self.config["state_location"],
|
get_config_dir(), "state",
|
||||||
torrent_id + ".fastresume"),
|
torrent_id + ".fastresume"),
|
||||||
"rb")
|
"rb")
|
||||||
fastresume = _file.read()
|
fastresume = _file.read()
|
||||||
|
@ -323,7 +323,7 @@ class TorrentManager(component.Component):
|
||||||
if not state.magnet:
|
if not state.magnet:
|
||||||
add_torrent_params["ti"] =\
|
add_torrent_params["ti"] =\
|
||||||
self.get_torrent_info_from_file(
|
self.get_torrent_info_from_file(
|
||||||
os.path.join(self.config["state_location"], state.torrent_id + ".torrent"))
|
os.path.join(get_config_dir(), "state", state.torrent_id + ".torrent"))
|
||||||
|
|
||||||
if not add_torrent_params["ti"]:
|
if not add_torrent_params["ti"]:
|
||||||
log.error("Unable to add torrent!")
|
log.error("Unable to add torrent!")
|
||||||
|
@ -412,7 +412,7 @@ class TorrentManager(component.Component):
|
||||||
# Write the .torrent file to the state directory
|
# Write the .torrent file to the state directory
|
||||||
if filedump:
|
if filedump:
|
||||||
try:
|
try:
|
||||||
save_file = open(os.path.join(self.config["state_location"],
|
save_file = open(os.path.join(get_config_dir(), "state",
|
||||||
torrent.torrent_id + ".torrent"),
|
torrent.torrent_id + ".torrent"),
|
||||||
"wb")
|
"wb")
|
||||||
save_file.write(filedump)
|
save_file.write(filedump)
|
||||||
|
@ -449,7 +449,7 @@ class TorrentManager(component.Component):
|
||||||
log.debug("Attempting to open %s for add.", torrent_id)
|
log.debug("Attempting to open %s for add.", torrent_id)
|
||||||
_file = open(
|
_file = open(
|
||||||
os.path.join(
|
os.path.join(
|
||||||
self.config["state_location"], torrent_id + ".torrent"),
|
get_config_dir(), "state", torrent_id + ".torrent"),
|
||||||
"rb")
|
"rb")
|
||||||
filedump = lt.bdecode(_file.read())
|
filedump = lt.bdecode(_file.read())
|
||||||
_file.close()
|
_file.close()
|
||||||
|
@ -462,22 +462,22 @@ class TorrentManager(component.Component):
|
||||||
def remove(self, torrent_id, remove_data=False):
|
def remove(self, torrent_id, remove_data=False):
|
||||||
"""
|
"""
|
||||||
Remove a torrent from the session.
|
Remove a torrent from the session.
|
||||||
|
|
||||||
:param torrent_id: the torrent to remove
|
:param torrent_id: the torrent to remove
|
||||||
:type torrent_id: string
|
:type torrent_id: string
|
||||||
:param remove_data: if True, remove the downloaded data
|
:param remove_data: if True, remove the downloaded data
|
||||||
:type remove_data: bool
|
:type remove_data: bool
|
||||||
|
|
||||||
:returns: True if removed successfully, False if not
|
:returns: True if removed successfully, False if not
|
||||||
:rtype: bool
|
:rtype: bool
|
||||||
|
|
||||||
:raises InvalidTorrentError: if the torrent_id is not in the session
|
:raises InvalidTorrentError: if the torrent_id is not in the session
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if torrent_id not in self.torrents:
|
if torrent_id not in self.torrents:
|
||||||
raise InvalidTorrentError("torrent_id not in session")
|
raise InvalidTorrentError("torrent_id not in session")
|
||||||
|
|
||||||
# Emit the signal to the clients
|
# Emit the signal to the clients
|
||||||
component.get("EventManager").emit(PreTorrentRemovedEvent(torrent_id))
|
component.get("EventManager").emit(PreTorrentRemovedEvent(torrent_id))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue