mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-02 22:48:40 +00:00
Add 'torrentfiles_location' configuration option.
This commit is contained in:
parent
ac08425ee3
commit
4ca1206b2c
4 changed files with 41 additions and 1 deletions
1
TODO
1
TODO
|
@ -14,7 +14,6 @@
|
||||||
* Add classic/normal mode to preferences
|
* Add classic/normal mode to preferences
|
||||||
* Implement 'Classic' mode
|
* Implement 'Classic' mode
|
||||||
* Tray tooltip
|
* Tray tooltip
|
||||||
* Add torrentfiles location config option
|
|
||||||
* Add autoload folder
|
* Add autoload folder
|
||||||
* Add wizard
|
* Add wizard
|
||||||
* Add a health indication to the statusbar
|
* Add a health indication to the statusbar
|
||||||
|
|
|
@ -46,6 +46,7 @@ class Config:
|
||||||
log.debug("Config created with filename: %s", filename)
|
log.debug("Config created with filename: %s", filename)
|
||||||
log.debug("Config defaults: %s", defaults)
|
log.debug("Config defaults: %s", defaults)
|
||||||
self.config = {}
|
self.config = {}
|
||||||
|
self.previous_config = {}
|
||||||
self.set_functions = {}
|
self.set_functions = {}
|
||||||
|
|
||||||
# If defaults is not None then we need to use "defaults".
|
# If defaults is not None then we need to use "defaults".
|
||||||
|
@ -115,6 +116,8 @@ class Config:
|
||||||
# Sets the "key" with "value" in the config dict
|
# Sets the "key" with "value" in the config dict
|
||||||
if self.config[key] != value:
|
if self.config[key] != value:
|
||||||
log.debug("Setting '%s' to %s of %s", key, value, type(value))
|
log.debug("Setting '%s' to %s of %s", key, value, type(value))
|
||||||
|
# Make a copy of the current config prior to changing it
|
||||||
|
self.previous_config = self.config.copy()
|
||||||
self.config[key] = value
|
self.config[key] = value
|
||||||
# Run the set_function for this key if any
|
# Run the set_function for this key if any
|
||||||
try:
|
try:
|
||||||
|
@ -139,6 +142,10 @@ class Config:
|
||||||
"""Returns the entire configuration as a dictionary."""
|
"""Returns the entire configuration as a dictionary."""
|
||||||
return self.config
|
return self.config
|
||||||
|
|
||||||
|
def get_previous_config(self):
|
||||||
|
"""Returns the config prior to the last set()"""
|
||||||
|
return self.previous_config
|
||||||
|
|
||||||
def register_set_function(self, key, function, apply_now=True):
|
def register_set_function(self, key, function, apply_now=True):
|
||||||
"""Register a function to be run when a config value changes."""
|
"""Register a function to be run when a config value changes."""
|
||||||
log.debug("Registering function for %s key..", key)
|
log.debug("Registering function for %s key..", key)
|
||||||
|
|
|
@ -36,6 +36,8 @@ import locale
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
import sys
|
import sys
|
||||||
import pickle
|
import pickle
|
||||||
|
import shutil
|
||||||
|
import os
|
||||||
|
|
||||||
import deluge.SimpleXMLRPCServer as SimpleXMLRPCServer
|
import deluge.SimpleXMLRPCServer as SimpleXMLRPCServer
|
||||||
from SocketServer import ThreadingMixIn
|
from SocketServer import ThreadingMixIn
|
||||||
|
@ -148,6 +150,8 @@ class Core(
|
||||||
self.session.add_extension(lt.create_metadata_plugin)
|
self.session.add_extension(lt.create_metadata_plugin)
|
||||||
|
|
||||||
# Register set functions in the Config
|
# Register set functions in the Config
|
||||||
|
self.config.register_set_function("torrentfiles_location",
|
||||||
|
self._on_set_torrentfiles_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("random_port",
|
self.config.register_set_function("random_port",
|
||||||
|
@ -426,6 +430,31 @@ class Core(
|
||||||
self.signals.emit("torrent_all_resumed", torrent_id)
|
self.signals.emit("torrent_all_resumed", torrent_id)
|
||||||
|
|
||||||
# Config set functions
|
# Config set functions
|
||||||
|
def _on_set_torrentfiles_location(self, key, value):
|
||||||
|
try:
|
||||||
|
old = self.config.get_previous_config()["torrentfiles_location"]
|
||||||
|
except Exception, e:
|
||||||
|
# This probably means it's not a real change but we're just loading
|
||||||
|
# the config.
|
||||||
|
log.debug("Unable to get previous torrentfiles_location: %s", e)
|
||||||
|
return
|
||||||
|
|
||||||
|
# First try to create the new directory
|
||||||
|
try:
|
||||||
|
os.makedirs(value)
|
||||||
|
except Exception, e:
|
||||||
|
log.debug("Unable to make directory: %s", e)
|
||||||
|
|
||||||
|
# Now copy all files in the old directory to the new one
|
||||||
|
for root, dirs, files in os.walk(old):
|
||||||
|
for dir in dirs:
|
||||||
|
os.makedirs(dir)
|
||||||
|
for file in files:
|
||||||
|
try:
|
||||||
|
shutil.copy2(os.path.join(root, file), value)
|
||||||
|
except Exception, e:
|
||||||
|
log.debug("Unable to copy file to %s: %s", value, 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:
|
||||||
|
|
|
@ -156,6 +156,8 @@ class Preferences(component.Component):
|
||||||
core_widgets = {
|
core_widgets = {
|
||||||
"download_path_button": \
|
"download_path_button": \
|
||||||
("filename", self.core_config["download_location"]),
|
("filename", self.core_config["download_location"]),
|
||||||
|
"torrent_files_button": \
|
||||||
|
("filename", self.core_config["torrentfiles_location"]),
|
||||||
"radio_compact_allocation": \
|
"radio_compact_allocation": \
|
||||||
("active", self.core_config["compact_allocation"]),
|
("active", self.core_config["compact_allocation"]),
|
||||||
"radio_full_allocation": \
|
"radio_full_allocation": \
|
||||||
|
@ -213,6 +215,7 @@ class Preferences(component.Component):
|
||||||
else:
|
else:
|
||||||
core_widget_list = [
|
core_widget_list = [
|
||||||
"download_path_button",
|
"download_path_button",
|
||||||
|
"torrent_files_button",
|
||||||
"radio_compact_allocation",
|
"radio_compact_allocation",
|
||||||
"radio_full_allocation",
|
"radio_full_allocation",
|
||||||
"chk_prioritize_first_last_pieces",
|
"chk_prioritize_first_last_pieces",
|
||||||
|
@ -306,6 +309,8 @@ class Preferences(component.Component):
|
||||||
self.glade.get_widget("radio_ask_save").get_active()
|
self.glade.get_widget("radio_ask_save").get_active()
|
||||||
new_core_config["download_location"] = \
|
new_core_config["download_location"] = \
|
||||||
self.glade.get_widget("download_path_button").get_filename()
|
self.glade.get_widget("download_path_button").get_filename()
|
||||||
|
new_core_config["torrentfiles_location"] = \
|
||||||
|
self.glade.get_widget("torrent_files_button").get_filename()
|
||||||
new_core_config["compact_allocation"] = \
|
new_core_config["compact_allocation"] = \
|
||||||
self.glade.get_widget("radio_compact_allocation").get_active()
|
self.glade.get_widget("radio_compact_allocation").get_active()
|
||||||
new_core_config["prioritize_first_last_pieces"] = \
|
new_core_config["prioritize_first_last_pieces"] = \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue