gtg team mailing list archive
-
gtg team
-
Mailing list archive
-
Message #03786
[Merge] lp:~izidor/gtg/default_preferences_plugins into lp:gtg
Izidor Matušov has proposed merging lp:~izidor/gtg/default_preferences_plugins into lp:gtg.
Requested reviews:
Gtg developers (gtg)
Related bugs:
Bug #1094307 in Getting Things GNOME!: "Missing new preferences for plugins"
https://bugs.launchpad.net/gtg/+bug/1094307
For more details, see:
https://code.launchpad.net/~izidor/gtg/default_preferences_plugins/+merge/143403
Plugin API now takes care about default values of preferences, thus simplify lives of plugin creators (by removing couple lines to write :)
--
https://code.launchpad.net/~izidor/gtg/default_preferences_plugins/+merge/143403
Your team Gtg developers is requested to review the proposed merge of lp:~izidor/gtg/default_preferences_plugins into lp:gtg.
=== modified file 'CHANGELOG'
--- CHANGELOG 2013-01-13 20:14:19 +0000
+++ CHANGELOG 2013-01-15 21:00:30 +0000
@@ -11,6 +11,7 @@
* Fix for bug #1096622: Damaged image in the help, by Parin Porecha
* Fix for bug #1095390: Quick Add bar incorrectly parses tags, by Parin Porecha
* Fix for bug #1079143: Adding the same custom color in tag editor multiple times raises an Exception, by Parin Porecha
+ * Better handling of preferences loading (bug #1094307)
2012-11-06 Getting Things GNOME! 0.3
* Hide tasks with due date someday, #931376
=== modified file 'GTG/core/plugins/api.py'
--- GTG/core/plugins/api.py 2012-12-18 13:01:11 +0000
+++ GTG/core/plugins/api.py 2013-01-15 21:00:30 +0000
@@ -209,8 +209,13 @@
pane.basetree.get_basetree().refresh_all()
#=== file saving/loading ======================================================
- def load_configuration_object(self, plugin_name, filename, \
- basedir=xdg_config_home):
+ def load_configuration_object(self, plugin_name, filename,
+ basedir=xdg_config_home, default_values=None):
+ if default_values is not None:
+ result = dict(default_values)
+ else:
+ result = dict()
+
dirname = os.path.join(basedir, 'gtg/plugins', plugin_name)
path = os.path.join(dirname, filename)
if os.path.isdir(dirname):
@@ -218,12 +223,14 @@
try:
with open(path, 'r') as file:
item = pickle.load(file)
+ result.update(item)
except:
- return None
- return item
+ pass
else:
os.makedirs(dirname)
+ return result
+
def save_configuration_object(self, plugin_name, filename, item, \
basedir=xdg_config_home):
dirname = os.path.join(basedir, 'gtg/plugins', plugin_name)
=== modified file 'GTG/plugins/export/export.py'
--- GTG/plugins/export/export.py 2012-08-11 12:24:49 +0000
+++ GTG/plugins/export/export.py 2013-01-15 21:00:30 +0000
@@ -366,12 +366,9 @@
def _preferences_load(self):
""" Restore user preferences """
- data = self.plugin_api.load_configuration_object(
- self.PLUGIN_NAME, "preferences")
- if type(data) != type(dict()):
- self.preferences = self.DEFAULT_PREFERENCES
- else:
- self.preferences = data
+ self.preferences = self.plugin_api.load_configuration_object(
+ self.PLUGIN_NAME, "preferences",
+ default_values = self.DEFAULT_PREFERENCES)
def _preferences_store(self):
""" Store user preferences """
=== modified file 'GTG/plugins/hamster/hamster.py'
--- GTG/plugins/hamster/hamster.py 2012-11-25 19:19:44 +0000
+++ GTG/plugins/hamster/hamster.py 2013-01-15 21:00:30 +0000
@@ -307,13 +307,9 @@
return True
def preferences_load(self):
- data = self.plugin_api.load_configuration_object(
- self.PLUGIN_NAMESPACE, "preferences")
- self.preferences = {}
- self.preferences.update(self.DEFAULT_PREFERENCES)
-
- if type(data) == type(dict()):
- self.preferences.update(data)
+ self.preferences = self.plugin_api.load_configuration_object(
+ self.PLUGIN_NAME, "preferences",
+ default_values = self.DEFAULT_PREFERENCES)
def preferences_store(self):
self.plugin_api.save_configuration_object(self.PLUGIN_NAMESPACE,
=== modified file 'GTG/plugins/notification_area/notification_area.py'
--- GTG/plugins/notification_area/notification_area.py 2012-12-16 14:59:32 +0000
+++ GTG/plugins/notification_area/notification_area.py 2013-01-15 21:00:30 +0000
@@ -385,13 +385,9 @@
### Preferences methods #######################################################
def preferences_load(self):
- data = self.__plugin_api.load_configuration_object(self.PLUGIN_NAME,
- "preferences")
- # We first load the preferences then update the dict
- # This way new default options are recognized with old cfg files
- self.preferences = self.DEFAULT_PREFERENCES
- if isinstance(data, dict):
- self.preferences.update(data)
+ self.preferences = self.__plugin_api.load_configuration_object(
+ self.PLUGIN_NAME, "preferences",
+ default_values = self.DEFAULT_PREFERENCES)
def preferences_store(self):
self.__plugin_api.save_configuration_object(self.PLUGIN_NAME,
=== modified file 'GTG/plugins/task_reaper/reaper.py'
--- GTG/plugins/task_reaper/reaper.py 2012-07-13 17:24:28 +0000
+++ GTG/plugins/task_reaper/reaper.py 2013-01-15 21:00:30 +0000
@@ -165,12 +165,9 @@
self.preferences_dialog.hide()
def preferences_load(self):
- data = self.plugin_api.load_configuration_object(self.PLUGIN_NAME,
- "preferences")
- if data == None or type(data) != type(dict()):
- self.preferences = self.DEFAULT_PREFERENCES
- else:
- self.preferences = data
+ self.preferences = self.plugin_api.load_configuration_object(
+ self.PLUGIN_NAME, "preferences",
+ default_values = self.DEFAULT_PREFERENCES)
def preferences_store(self):
self.plugin_api.save_configuration_object(self.PLUGIN_NAME,
=== modified file 'GTG/plugins/untouched_tasks/untouchedTasks.py'
--- GTG/plugins/untouched_tasks/untouchedTasks.py 2012-12-14 12:14:01 +0000
+++ GTG/plugins/untouched_tasks/untouchedTasks.py 2013-01-15 21:00:30 +0000
@@ -180,12 +180,9 @@
self.preferences_dialog.hide()
def preferences_load(self):
- data = self.plugin_api.load_configuration_object(self.PLUGIN_NAME,
- "preferences")
- if data == None or type(data) != type(dict()):
- self.preferences = self.DEFAULT_PREFERENCES
- else:
- self.preferences = data
+ self.preferences = self.plugin_api.load_configuration_object(
+ self.PLUGIN_NAME, "preferences",
+ default_values = self.DEFAULT_PREFERENCES)
def preferences_store(self):
self.plugin_api.save_configuration_object(self.PLUGIN_NAME,
=== modified file 'GTG/plugins/urgency_color/urgency_color.py'
--- GTG/plugins/urgency_color/urgency_color.py 2012-12-23 08:47:15 +0000
+++ GTG/plugins/urgency_color/urgency_color.py 2013-01-15 21:00:30 +0000
@@ -212,27 +212,19 @@
self.prefs_update_widgets()
def prefs_load(self):
- data = self._plugin_api.load_configuration_object( \
- self.PLUGIN_NAME,
- 'preferences')
- if not data or not isinstance(data, dict):
- self._pref_data = dict(self.DEFAULT_PREFS)
- else:
- # CORRECT NAMES FROM OLD PREFERENCES
- # This is a dirty fix and thus should be removed in a
- # distant future, when nobody has "red", "yellow" or "green"
- # settings
- namepairs = {'red':'high','yellow':'normal','green':'low'}
- for key,val in data.iteritems():
- for oldname,newname in namepairs.iteritems():
- if key == "color_"+oldname:
- data['color_'+newname] = data.pop(key)
- # Add new preferences where not present
- for setting in self.DEFAULT_PREFS.iterkeys():
- if setting not in data:
- data[setting] = self.DEFAULT_PREFS[setting]
- self._pref_data = dict(data)
+ self._pref_data = self._plugin_api.load_configuration_object(
+ self.PLUGIN_NAME, "preferences",
+ default_values = self.DEFAULT_PREFS)
+ # CORRECT NAMES FROM OLD PREFERENCES
+ # This is a dirty fix and thus should be removed in a
+ # distant future, when nobody has "red", "yellow" or "green"
+ # settings
+ namepairs = {'red':'high', 'yellow':'normal', 'green':'low'}
+ for oldname, newname in namepairs.iteritems():
+ old_key, new_key = "color_" + oldname, "color_" + newname
+ if old_key in self._pref_data:
+ self._pref_data[new_key] = self._pref_data.pop(old_key)
def prefs_store(self):
self._plugin_api.save_configuration_object( \
Follow ups