diff options
author | Scott Murray <scott.murray@konsulko.com> | 2024-05-27 12:09:15 -0400 |
---|---|---|
committer | Scott Murray <scott.murray@konsulko.com> | 2024-05-27 16:18:23 +0000 |
commit | 617a152fa89c9bdb1538c1707f62501847223e04 (patch) | |
tree | 0f4f1bf89b0022dceb6a6123fcc21390b0e0b439 /extras | |
parent | 08857a681022abf61330ce5b59d636f5cf446eba (diff) |
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 <scott.murray@konsulko.com>
(cherry picked from commit 157db1c70f6bcd4d43b26d22133dec380f504483)
Diffstat (limited to 'extras')
-rw-r--r-- | extras/config.py | 10 |
1 files changed, 8 insertions, 2 deletions
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) |