From: Scott Murray Date: Mon, 27 May 2024 16:09:15 +0000 (-0400) Subject: Rework configuration saving X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=commitdiff_plain;h=157db1c70f6bcd4d43b26d22133dec380f504483;p=src%2Fagl-demo-control-panel.git Rework configuration saving Rework configuration file saving to always save to the user's local configuration directory (i.e. $HOME/.local/...), and to try loading from that location first. This allows installing initial default configurations in /etc, while still allowing user overrides. Bug-AGL: SPEC-5138 Change-Id: I03a8f0ea31b5217936fb4aab888519117977e0ef Signed-off-by: Scott Murray --- diff --git a/extras/config.py b/extras/config.py index d901a8e..b1b1d7d 100644 --- a/extras/config.py +++ b/extras/config.py @@ -25,10 +25,13 @@ def check_paths(*paths): return {path: os.path.exists(path) for path in paths} +USER_CONFIG_PATH = os.path.join(os.path.expanduser("~"), + ".local/share/agl-demo-control-panel/config.ini") + CONFIG_PATHS = check_paths( + USER_CONFIG_PATH, + "/etc/agl-demo-control-panel/config.ini", "/etc/agl-demo-control-panel.ini", - os.path.join(os.path.expanduser("~"), - ".local/share/agl-demo-control-panel/config.ini"), os.path.abspath(os.path.join(os.path.dirname(__file__), 'config.ini')) ) @@ -132,6 +135,9 @@ def save_config(new_config, auth_token, CA_File=None): else: config.set('vss-server', 'cacert', str(CA_File)) + # Always save to the user config + config_path = USER_CONFIG_PATH + os.makedirs(os.path.dirname(config_path), exist_ok=True) with open(config_path, 'w') as configfile: config.write(configfile)