From 03a6da611538f80517b81ddf6e3ef560ed00a752 Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Wed, 8 Jan 2025 13:11:12 +0700 Subject: [PATCH] #4461 add 'setting' subcommand for modifying config --- xpra/scripts/main.py | 24 ++++++++++++++++++++++-- xpra/util/config.py | 2 +- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/xpra/scripts/main.py b/xpra/scripts/main.py index 3d5381ba37..111bcb7b55 100755 --- a/xpra/scripts/main.py +++ b/xpra/scripts/main.py @@ -482,10 +482,10 @@ def run_mode(script_file: str, cmdline, error_cb, options, args, full_mode: str, "compression", "packet-encoding", "path-info", "printing-info", "version-info", "version-check", "toolbox", "initenv", "setup-ssl", "show-ssl", - "auth", "showconfig", "showsetting", + "auth", "applications-menu", "sessions-menu", "_proxy", - "configure", + "configure", "showconfig", "showsetting", "setting", "wait-for-x11", "wait-for-wayland", "xvfb-command", "xvfb", ): @@ -887,6 +887,8 @@ def do_run_mode(script_file: str, cmdline, error_cb, options, args, full_mode: s return run_showconfig(options, args) if mode == "showsetting": return run_showsetting(args) + if mode == "setting": + return run_setting(args) # unknown subcommand: if mode != "help": print(f"Invalid subcommand {mode!r}") @@ -4673,6 +4675,24 @@ def show_settings() -> None: return 0 +def run_setting(args) -> ExitValue: + if len(args) < 2: + raise InitException("specify a setting to modify and its value") + setting = args[0] + otype = OPTION_TYPES.get(setting) + if not otype: + raise ValueError(f"{setting!r} is not a valid setting, see `xpra showconfig`") + if otype == list: + value = args[1:] + else: + if len(args) > 2: + raise ValueError(f"too many values for {setting!r} which is a {otype!r}") + value = args[1] + from xpra.util.config import update_config_attribute + update_config_attribute(setting, value) + return ExitCode.OK + + if __name__ == "__main__": # pragma: no cover code = main("xpra.exe", sys.argv) if not code: diff --git a/xpra/util/config.py b/xpra/util/config.py index e0101f9174..95556ad401 100644 --- a/xpra/util/config.py +++ b/xpra/util/config.py @@ -55,7 +55,7 @@ def save_user_config_file(options: dict, f.write(f"{k} = {item}\n") -def update_config_attribute(attribute: str, value: str | int | float, +def update_config_attribute(attribute: str, value: str | int | float | list, dirname="conf.d", filename=CONFIGURE_TOOL_CONFIG) -> None: config = parse_user_config_file(dirname, filename) value_str = str(value)