[GRASS-SVN] r59173 - grass/trunk/lib/python/script

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Mar 2 23:34:50 PST 2014


Author: lucadelu
Date: 2014-03-02 23:34:50 -0800 (Sun, 02 Mar 2014)
New Revision: 59173

Modified:
   grass/trunk/lib/python/script/core.py
Log:
script/core.py: fix bug in compare_key_value_text_files

Modified: grass/trunk/lib/python/script/core.py
===================================================================
--- grass/trunk/lib/python/script/core.py	2014-03-03 03:53:36 UTC (rev 59172)
+++ grass/trunk/lib/python/script/core.py	2014-03-03 07:34:50 UTC (rev 59173)
@@ -901,7 +901,7 @@
     @param precision precision with which the floating point values are compared
     @param proj True if it has to check some information about projection system
     @param units True if it has to check some information about units
-    
+
     @return True if full or almost identical, False if different
     """
     dict_a = _text_to_key_value_dict(filename_a, sep, checkproj=proj,
@@ -909,34 +909,26 @@
     dict_b = _text_to_key_value_dict(filename_b, sep, checkproj=proj,
                                      checkunits=units)
 
-    missing_keys = 0
+    if sorted(dict_a.keys()) != sorted(dict_b.keys()):
+        return False
 
     # We compare matching keys
     for key in dict_a.keys():
-        if key in dict_b:
-            # Floating point values must be handled separately
-            if isinstance(dict_a[key], float) and isinstance(dict_b[key], float):
-                if abs(dict_a[key] - dict_b[key]) > precision:
-                    return False
-            elif isinstance(dict_a[key], float) or isinstance(dict_b[key], float):
-                warning(_("Mixing value types. Will try to compare after "
-                          "integer conversion"))
-                return int(dict_a[key]) == int(dict_b[key])
-            elif key == "+towgs84":
-                # We compare the sum of the entries
-                if abs(sum(dict_a[key]) - sum(dict_b[key])) > precision:
-                    return False
-            else:
-                if dict_a[key] != dict_b[key]:
-                    return False
+        # Floating point values must be handled separately
+        if isinstance(dict_a[key], float) and isinstance(dict_b[key], float):
+            if abs(dict_a[key] - dict_b[key]) > precision:
+                return False
+        elif isinstance(dict_a[key], float) or isinstance(dict_b[key], float):
+            warning(_("Mixing value types. Will try to compare after "
+                      "integer conversion"))
+            return int(dict_a[key]) == int(dict_b[key])
+        elif key == "+towgs84":
+            # We compare the sum of the entries
+            if abs(sum(dict_a[key]) - sum(dict_b[key])) > precision:
+                return False
         else:
-            missing_keys += 1
-    if missing_keys == len(dict_a):
-        return False
-    if missing_keys > 0:
-        warning(_("Several keys (%(miss)i out of %(a)i) are missing "
-                  "in the target file") % {'miss': missing_keys,
-                                           'a': len(dict_a)})
+            if dict_a[key] != dict_b[key]:
+                return False
     return True
 
 def diff_files(filename_a, filename_b):



More information about the grass-commit mailing list