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_"`.
This commit is contained in:
Alex Pyrgiotis 2023-07-04 13:38:09 +03:00
parent 2df459bcfc
commit 266addb5b7
No known key found for this signature in database
GPG key ID: B6C15EBA0357C9AA

View file

@ -43,8 +43,16 @@ class Settings:
def get(self, key: str) -> Any: def get(self, key: str) -> Any:
return self.settings[key] 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 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: def load(self) -> None:
if os.path.isfile(self.settings_filename): if os.path.isfile(self.settings_filename):