[GRASS-SVN] r52719 - grass/trunk/gui/wxpython/core

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Aug 17 09:47:02 PDT 2012


Author: martinl
Date: 2012-08-17 09:47:02 -0700 (Fri, 17 Aug 2012)
New Revision: 52719

Modified:
   grass/trunk/gui/wxpython/core/settings.py
Log:
wxGUI/settings: Append() - add overwrite argument


Modified: grass/trunk/gui/wxpython/core/settings.py
===================================================================
--- grass/trunk/gui/wxpython/core/settings.py	2012-08-17 16:21:11 UTC (rev 52718)
+++ grass/trunk/gui/wxpython/core/settings.py	2012-08-17 16:47:02 UTC (rev 52719)
@@ -1081,7 +1081,7 @@
         except KeyError:
             raise GException("%s '%s:%s:%s'" % (_("Unable to set "), group, key, subkey))
         
-    def Append(self, dict, group, key, subkey, value):
+    def Append(self, dict, group, key, subkey, value, overwrite = True):
         """!Set value of key/subkey
 
         Create group/key/subkey if not exists
@@ -1091,25 +1091,33 @@
         @param key key
         @param subkey subkey (value or list)
         @param value value
+        @param overwrite True to overwrite existing value
         """
+        hasValue = True
         if group not in dict:
             dict[group] = {}
-
+            hasValue = False
+        
         if key not in dict[group]:
             dict[group][key] = {}
-
+            hasValue = False
+        
         if type(subkey) == types.ListType:
             # TODO: len(subkey) > 2
             if subkey[0] not in dict[group][key]:
                 dict[group][key][subkey[0]] = {}
+                hasValue = False
+            
             try:
-                dict[group][key][subkey[0]][subkey[1]] = value
+                if overwrite or (not overwrite and not hasValue):
+                    dict[group][key][subkey[0]][subkey[1]] = value
             except TypeError:
                 print >> sys.stderr, _("Unable to parse settings '%s'") % value + \
                     ' (' + group + ':' + key + ':' + subkey[0] + ':' + subkey[1] + ')'
         else:
             try:
-                dict[group][key][subkey] = value
+                if overwrite or (not overwrite and not hasValue):
+                    dict[group][key][subkey] = value
             except TypeError:
                 print >> sys.stderr, _("Unable to parse settings '%s'") % value + \
                     ' (' + group + ':' + key + ':' + subkey + ')'



More information about the grass-commit mailing list