aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorScott Murray <scott.murray@konsulko.com>2024-05-27 12:09:15 -0400
committerScott Murray <scott.murray@konsulko.com>2024-05-27 12:16:10 -0400
commit157db1c70f6bcd4d43b26d22133dec380f504483 (patch)
tree0ca5cbdb325628396d369781f437a3e79eb180d0
parent7a4d074377f1ee424b1d31302de92e1d510611a3 (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>
-rw-r--r--extras/config.py10
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)