From 266addb5b71075fc64077a68e77c7b742e8a3f0e Mon Sep 17 00:00:00 2001 From: Alex Pyrgiotis Date: Tue, 4 Jul 2023 13:38:09 +0300 Subject: [PATCH] Make it easier to get and save updater settings Add the following two features in the Settings class: 1. Add a way to save the settings, if the contents of a key have changed. 2. Add a way to get all the updater settings, by getting fetching the keys that start with `"updater_"`. --- dangerzone/settings.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/dangerzone/settings.py b/dangerzone/settings.py index 877dc39..49db150 100644 --- a/dangerzone/settings.py +++ b/dangerzone/settings.py @@ -43,8 +43,16 @@ class Settings: def get(self, key: str) -> Any: return self.settings[key] - def set(self, key: str, val: Any) -> None: + def set(self, key: str, val: Any, autosave: bool = False) -> None: + old_val = self.get(key) self.settings[key] = val + if autosave and val != old_val: + self.save() + + def get_updater_settings(self) -> Dict[str, Any]: + return { + key: val for key, val in self.settings.items() if key.startswith("updater_") + } def load(self) -> None: if os.path.isfile(self.settings_filename):