mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-11 12:04:10 +00:00
Add 'torrentfiles_location' configuration option.
This commit is contained in:
parent
ac08425ee3
commit
4ca1206b2c
1
TODO
1
TODO
@ -14,7 +14,6 @@
|
||||
* Add classic/normal mode to preferences
|
||||
* Implement 'Classic' mode
|
||||
* Tray tooltip
|
||||
* Add torrentfiles location config option
|
||||
* Add autoload folder
|
||||
* Add wizard
|
||||
* Add a health indication to the statusbar
|
||||
|
@ -46,6 +46,7 @@ class Config:
|
||||
log.debug("Config created with filename: %s", filename)
|
||||
log.debug("Config defaults: %s", defaults)
|
||||
self.config = {}
|
||||
self.previous_config = {}
|
||||
self.set_functions = {}
|
||||
|
||||
# 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
|
||||
if self.config[key] != 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
|
||||
# Run the set_function for this key if any
|
||||
try:
|
||||
@ -139,6 +142,10 @@ class Config:
|
||||
"""Returns the entire configuration as a dictionary."""
|
||||
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):
|
||||
"""Register a function to be run when a config value changes."""
|
||||
log.debug("Registering function for %s key..", key)
|
||||
|
@ -36,6 +36,8 @@ import locale
|
||||
import pkg_resources
|
||||
import sys
|
||||
import pickle
|
||||
import shutil
|
||||
import os
|
||||
|
||||
import deluge.SimpleXMLRPCServer as SimpleXMLRPCServer
|
||||
from SocketServer import ThreadingMixIn
|
||||
@ -148,6 +150,8 @@ class Core(
|
||||
self.session.add_extension(lt.create_metadata_plugin)
|
||||
|
||||
# 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._on_set_listen_ports)
|
||||
self.config.register_set_function("random_port",
|
||||
@ -426,6 +430,31 @@ class Core(
|
||||
self.signals.emit("torrent_all_resumed", torrent_id)
|
||||
|
||||
# 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):
|
||||
# Only set the listen ports if random_port is not true
|
||||
if self.config["random_port"] is not True:
|
||||
|
@ -156,6 +156,8 @@ class Preferences(component.Component):
|
||||
core_widgets = {
|
||||
"download_path_button": \
|
||||
("filename", self.core_config["download_location"]),
|
||||
"torrent_files_button": \
|
||||
("filename", self.core_config["torrentfiles_location"]),
|
||||
"radio_compact_allocation": \
|
||||
("active", self.core_config["compact_allocation"]),
|
||||
"radio_full_allocation": \
|
||||
@ -213,6 +215,7 @@ class Preferences(component.Component):
|
||||
else:
|
||||
core_widget_list = [
|
||||
"download_path_button",
|
||||
"torrent_files_button",
|
||||
"radio_compact_allocation",
|
||||
"radio_full_allocation",
|
||||
"chk_prioritize_first_last_pieces",
|
||||
@ -306,6 +309,8 @@ class Preferences(component.Component):
|
||||
self.glade.get_widget("radio_ask_save").get_active()
|
||||
new_core_config["download_location"] = \
|
||||
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"] = \
|
||||
self.glade.get_widget("radio_compact_allocation").get_active()
|
||||
new_core_config["prioritize_first_last_pieces"] = \
|
||||
|
Loading…
x
Reference in New Issue
Block a user