GTG

Merge lp:~izidor/gtg/default_preferences_plugins into lp:~gtg/gtg/old-trunk

Proposed by Izidor Matušov
Status: Merged
Merged at revision: 1277
Proposed branch: lp:~izidor/gtg/default_preferences_plugins
Merge into: lp:~gtg/gtg/old-trunk
Diff against target: 194 lines (+39/-56)
8 files modified
CHANGELOG (+1/-0)
GTG/core/plugins/api.py (+11/-4)
GTG/plugins/export/export.py (+3/-6)
GTG/plugins/hamster/hamster.py (+3/-7)
GTG/plugins/notification_area/notification_area.py (+3/-7)
GTG/plugins/task_reaper/reaper.py (+3/-6)
GTG/plugins/untouched_tasks/untouchedTasks.py (+3/-6)
GTG/plugins/urgency_color/urgency_color.py (+12/-20)
To merge this branch: bzr merge lp:~izidor/gtg/default_preferences_plugins
Reviewer Review Type Date Requested Status
Nimit Shah Approve
Gtg developers Pending
Review via email: mp+143403@code.launchpad.net

Description of the change

Plugin API now takes care about default values of preferences, thus simplify lives of plugin creators (by removing couple lines to write :)

To post a comment you must log in.
Revision history for this message
Nimit Shah (nimit-svnit) wrote :

Hi Izidor,
  The code looks proper to me.
  Just one small thing: Would "config" be a more intuitive variable name then "result"? Not an important question, you can always ignore it :)

1276. By Izidor Matušov

Rename result into config

Revision history for this message
Nimit Shah (nimit-svnit) wrote :

It is proper according to me :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'CHANGELOG'
--- CHANGELOG 2013-01-13 20:14:19 +0000
+++ CHANGELOG 2013-01-18 16:20:28 +0000
@@ -11,6 +11,7 @@
11 * Fix for bug #1096622: Damaged image in the help, by Parin Porecha11 * Fix for bug #1096622: Damaged image in the help, by Parin Porecha
12 * Fix for bug #1095390: Quick Add bar incorrectly parses tags, by Parin Porecha12 * Fix for bug #1095390: Quick Add bar incorrectly parses tags, by Parin Porecha
13 * Fix for bug #1079143: Adding the same custom color in tag editor multiple times raises an Exception, by Parin Porecha13 * Fix for bug #1079143: Adding the same custom color in tag editor multiple times raises an Exception, by Parin Porecha
14 * Better handling of preferences loading (bug #1094307)
1415
152012-11-06 Getting Things GNOME! 0.3162012-11-06 Getting Things GNOME! 0.3
16 * Hide tasks with due date someday, #93137617 * Hide tasks with due date someday, #931376
1718
=== 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-18 16:20:28 +0000
@@ -209,8 +209,13 @@
209 pane.basetree.get_basetree().refresh_all()209 pane.basetree.get_basetree().refresh_all()
210210
211#=== file saving/loading ======================================================211#=== file saving/loading ======================================================
212 def load_configuration_object(self, plugin_name, filename, \212 def load_configuration_object(self, plugin_name, filename,
213 basedir=xdg_config_home):213 basedir=xdg_config_home, default_values=None):
214 if default_values is not None:
215 config = dict(default_values)
216 else:
217 config = dict()
218
214 dirname = os.path.join(basedir, 'gtg/plugins', plugin_name)219 dirname = os.path.join(basedir, 'gtg/plugins', plugin_name)
215 path = os.path.join(dirname, filename)220 path = os.path.join(dirname, filename)
216 if os.path.isdir(dirname):221 if os.path.isdir(dirname):
@@ -218,12 +223,14 @@
218 try:223 try:
219 with open(path, 'r') as file:224 with open(path, 'r') as file:
220 item = pickle.load(file)225 item = pickle.load(file)
226 config.update(item)
221 except:227 except:
222 return None228 pass
223 return item
224 else:229 else:
225 os.makedirs(dirname)230 os.makedirs(dirname)
226231
232 return config
233
227 def save_configuration_object(self, plugin_name, filename, item, \234 def save_configuration_object(self, plugin_name, filename, item, \
228 basedir=xdg_config_home):235 basedir=xdg_config_home):
229 dirname = os.path.join(basedir, 'gtg/plugins', plugin_name)236 dirname = os.path.join(basedir, 'gtg/plugins', plugin_name)
230237
=== 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-18 16:20:28 +0000
@@ -366,12 +366,9 @@
366366
367 def _preferences_load(self):367 def _preferences_load(self):
368 """ Restore user preferences """368 """ Restore user preferences """
369 data = self.plugin_api.load_configuration_object(369 self.preferences = self.plugin_api.load_configuration_object(
370 self.PLUGIN_NAME, "preferences")370 self.PLUGIN_NAME, "preferences",
371 if type(data) != type(dict()):371 default_values = self.DEFAULT_PREFERENCES)
372 self.preferences = self.DEFAULT_PREFERENCES
373 else:
374 self.preferences = data
375372
376 def _preferences_store(self):373 def _preferences_store(self):
377 """ Store user preferences """374 """ Store user preferences """
378375
=== 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-18 16:20:28 +0000
@@ -307,13 +307,9 @@
307 return True307 return True
308308
309 def preferences_load(self):309 def preferences_load(self):
310 data = self.plugin_api.load_configuration_object(310 self.preferences = self.plugin_api.load_configuration_object(
311 self.PLUGIN_NAMESPACE, "preferences")311 self.PLUGIN_NAME, "preferences",
312 self.preferences = {}312 default_values = self.DEFAULT_PREFERENCES)
313 self.preferences.update(self.DEFAULT_PREFERENCES)
314
315 if type(data) == type(dict()):
316 self.preferences.update(data)
317313
318 def preferences_store(self):314 def preferences_store(self):
319 self.plugin_api.save_configuration_object(self.PLUGIN_NAMESPACE,315 self.plugin_api.save_configuration_object(self.PLUGIN_NAMESPACE,
320316
=== 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-18 16:20:28 +0000
@@ -385,13 +385,9 @@
385385
386### Preferences methods #######################################################386### Preferences methods #######################################################
387 def preferences_load(self):387 def preferences_load(self):
388 data = self.__plugin_api.load_configuration_object(self.PLUGIN_NAME,388 self.preferences = self.__plugin_api.load_configuration_object(
389 "preferences")389 self.PLUGIN_NAME, "preferences",
390 # We first load the preferences then update the dict390 default_values = self.DEFAULT_PREFERENCES)
391 # This way new default options are recognized with old cfg files
392 self.preferences = self.DEFAULT_PREFERENCES
393 if isinstance(data, dict):
394 self.preferences.update(data)
395391
396 def preferences_store(self):392 def preferences_store(self):
397 self.__plugin_api.save_configuration_object(self.PLUGIN_NAME,393 self.__plugin_api.save_configuration_object(self.PLUGIN_NAME,
398394
=== 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-18 16:20:28 +0000
@@ -165,12 +165,9 @@
165 self.preferences_dialog.hide()165 self.preferences_dialog.hide()
166166
167 def preferences_load(self):167 def preferences_load(self):
168 data = self.plugin_api.load_configuration_object(self.PLUGIN_NAME,168 self.preferences = self.plugin_api.load_configuration_object(
169 "preferences")169 self.PLUGIN_NAME, "preferences",
170 if data == None or type(data) != type(dict()):170 default_values = self.DEFAULT_PREFERENCES)
171 self.preferences = self.DEFAULT_PREFERENCES
172 else:
173 self.preferences = data
174171
175 def preferences_store(self):172 def preferences_store(self):
176 self.plugin_api.save_configuration_object(self.PLUGIN_NAME,173 self.plugin_api.save_configuration_object(self.PLUGIN_NAME,
177174
=== 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-18 16:20:28 +0000
@@ -180,12 +180,9 @@
180 self.preferences_dialog.hide()180 self.preferences_dialog.hide()
181181
182 def preferences_load(self):182 def preferences_load(self):
183 data = self.plugin_api.load_configuration_object(self.PLUGIN_NAME,183 self.preferences = self.plugin_api.load_configuration_object(
184 "preferences")184 self.PLUGIN_NAME, "preferences",
185 if data == None or type(data) != type(dict()):185 default_values = self.DEFAULT_PREFERENCES)
186 self.preferences = self.DEFAULT_PREFERENCES
187 else:
188 self.preferences = data
189186
190 def preferences_store(self):187 def preferences_store(self):
191 self.plugin_api.save_configuration_object(self.PLUGIN_NAME,188 self.plugin_api.save_configuration_object(self.PLUGIN_NAME,
192189
=== 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-18 16:20:28 +0000
@@ -212,27 +212,19 @@
212 self.prefs_update_widgets()212 self.prefs_update_widgets()
213213
214 def prefs_load(self):214 def prefs_load(self):
215 data = self._plugin_api.load_configuration_object( \215 self._pref_data = self._plugin_api.load_configuration_object(
216 self.PLUGIN_NAME,216 self.PLUGIN_NAME, "preferences",
217 'preferences')217 default_values = self.DEFAULT_PREFS)
218 if not data or not isinstance(data, dict):
219 self._pref_data = dict(self.DEFAULT_PREFS)
220 else:
221 # CORRECT NAMES FROM OLD PREFERENCES
222 # This is a dirty fix and thus should be removed in a
223 # distant future, when nobody has "red", "yellow" or "green"
224 # settings
225 namepairs = {'red':'high','yellow':'normal','green':'low'}
226 for key,val in data.iteritems():
227 for oldname,newname in namepairs.iteritems():
228 if key == "color_"+oldname:
229 data['color_'+newname] = data.pop(key)
230 # Add new preferences where not present
231 for setting in self.DEFAULT_PREFS.iterkeys():
232 if setting not in data:
233 data[setting] = self.DEFAULT_PREFS[setting]
234 self._pref_data = dict(data)
235218
219 # CORRECT NAMES FROM OLD PREFERENCES
220 # This is a dirty fix and thus should be removed in a
221 # distant future, when nobody has "red", "yellow" or "green"
222 # settings
223 namepairs = {'red':'high', 'yellow':'normal', 'green':'low'}
224 for oldname, newname in namepairs.iteritems():
225 old_key, new_key = "color_" + oldname, "color_" + newname
226 if old_key in self._pref_data:
227 self._pref_data[new_key] = self._pref_data.pop(old_key)
236228
237 def prefs_store(self):229 def prefs_store(self):
238 self._plugin_api.save_configuration_object( \230 self._plugin_api.save_configuration_object( \

Subscribers

People subscribed via source and target branches

to status/vote changes: