Skip to content

Commit

Permalink
#4461 add 'setting' subcommand for modifying config
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Jan 8, 2025
1 parent 15035b1 commit 03a6da6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
24 changes: 22 additions & 2 deletions xpra/scripts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
):
Expand Down Expand Up @@ -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}")
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion xpra/util/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 03a6da6

Please sign in to comment.