diff --git a/deluge/core/core.py b/deluge/core/core.py index aae44c83b..c66a88359 100644 --- a/deluge/core/core.py +++ b/deluge/core/core.py @@ -72,10 +72,15 @@ from deluge.core.eventmanager import EventManager from deluge.core.rpcserver import export class Core(component.Component): - def __init__(self, listen_interface=None): + def __init__(self, listen_interface=None, read_only_config_keys=None): log.debug("Core init..") component.Component.__init__(self, "Core") + # These keys will be dropped from the set_config() RPC and are + # configurable from the command-line. + self.read_only_config_keys = read_only_config_keys + log.debug("read_only_config_keys: %s", read_only_config_keys) + # Start the libtorrent session log.info("Starting libtorrent %s session..", lt.version) @@ -502,6 +507,8 @@ class Core(component.Component): """Set the config with values from dictionary""" # Load all the values into the configuration for key in config.keys(): + if self.read_only_config_keys and key in self.read_only_config_keys: + continue if isinstance(config[key], unicode) or isinstance(config[key], str): config[key] = config[key].encode("utf8") self.config[key] = config[key] diff --git a/deluge/core/daemon.py b/deluge/core/daemon.py index 1cb573c41..1dfea8dcb 100644 --- a/deluge/core/daemon.py +++ b/deluge/core/daemon.py @@ -133,9 +133,15 @@ class Daemon(object): else: listen_interface = "" + if options and options.read_only_config_keys: + read_only_config_keys = options.read_only_config_keys.split(",") + else: + read_only_config_keys = [] + from deluge.core.core import Core # Start the core as a thread and join it until it's done - self.core = Core(listen_interface=listen_interface) + self.core = Core(listen_interface=listen_interface, + read_only_config_keys=read_only_config_keys) port = self.core.config["daemon_port"] if options and options.port: diff --git a/deluge/main.py b/deluge/main.py index 26cbbbeb5..cf31a52fb 100644 --- a/deluge/main.py +++ b/deluge/main.py @@ -169,6 +169,9 @@ this should be an IP address", metavar="IFACE", help="Sets the log level to 'none', this is the same as `-L none`", action="store_true", default=False) parser.add_option("--profile", dest="profile", action="store_true", default=False, help="Profiles the daemon") + parser.add_option("--read-only-config-keys", dest="read_only_config_keys", + help="List of comma-separated config keys that will not be modified by set_config RPC.", + action="store", type="str") # Get the options and args from the OptionParser (options, args) = parser.parse_args() diff --git a/tests/test_core.py b/tests/test_core.py index 1cee17c63..4ecd8f9d3 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -13,6 +13,7 @@ from deluge.core.core import Core import deluge.component as component import deluge.error + class CoreTestCase(unittest.TestCase): def setUp(self): common.set_tmp_config_dir() @@ -148,3 +149,15 @@ class CoreTestCase(unittest.TestCase): for key in pathlist: self.assertEquals(deluge.core.torrent.sanitize_filepath(key, folder=False), pathlist[key]) self.assertEquals(deluge.core.torrent.sanitize_filepath(key, folder=True), pathlist[key] + '/') + + def test_read_only_config_keys(self): + key = 'max_upload_speed' + self.core.read_only_config_keys = [key] + + old_value = self.core.get_config_value(key) + self.core.set_config({key: old_value + 10}) + new_value = self.core.get_config_value(key) + + self.assertEquals(old_value, new_value) + + self.core.read_only_config_keys = None \ No newline at end of file