aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2010-01-20 19:15:02 -0500
committerW. Trevor King <wking@drexel.edu>2010-01-20 19:15:02 -0500
commitbe2de86f947b7bf2bb44f415df0a6f685633a64b (patch)
treea1c80ea8eb4b22974c7cec970711116787f648e5
parentca10c6d19b515bae54dcdfe44c65c32e57ac018b (diff)
downloadbugseverywhere-be2de86f947b7bf2bb44f415df0a6f685633a64b.tar.gz
Fix not-yet-loaded bug in SavedSettingsObject._get_saved_settings()
The earlier implementation only copied in the currently loaded properties and the required ones. The new implementation copies in _all_ the non-default properties.
-rw-r--r--libbe/storage/util/settings_object.py25
1 files changed, 19 insertions, 6 deletions
diff --git a/libbe/storage/util/settings_object.py b/libbe/storage/util/settings_object.py
index 9f2b7af..181d4ab 100644
--- a/libbe/storage/util/settings_object.py
+++ b/libbe/storage/util/settings_object.py
@@ -204,18 +204,31 @@ class SavedSettingsObject(object):
self._settings_loaded = True
def save_settings(self):
- """Load the settings from disk."""
+ """Save the settings to disk."""
# Override. Should save the dict output of ._get_saved_settings()
settings = self._get_saved_settings()
pass # write settings to disk....
def _get_saved_settings(self):
+ """
+ In order to avoid overwriting unread on-disk data, make sure
+ we've loaded anything sitting on the disk. In the current
+ implementation, all the settings are stored in a single file,
+ so we need to load _all_ the saved settings. Another approach
+ would be per-setting saves, in which case you could skip this
+ step, since any setting changes would have forced that setting
+ load already.
+ """
settings = {}
- for k,v in self.settings.items():
- if v != None and v != EMPTY:
- settings[k] = v
- for k in self.required_saved_properties:
- settings[k] = getattr(self, self._setting_name_to_attr_name(k))
+ for k in self.settings_properties:
+ if k in self.settings and \
+ not self.settings[k] in [None, EMPTY]:
+ settings[k] = self.settings[k]
+ else:
+ value = getattr(
+ self, self._setting_name_to_attr_name(k))
+ if value not in [None, EMPTY, []]:
+ settings[k] = value
return settings
def clear_cached_setting(self, setting=None):