From 617a152fa89c9bdb1538c1707f62501847223e04 Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Mon, 27 May 2024 12:09:15 -0400 Subject: 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 (cherry picked from commit 157db1c70f6bcd4d43b26d22133dec380f504483) --- extras/config.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'extras') 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) -- cgit 1.2.3-korg