[Erp5-report] r35579 nicolas - /erp5/trunk/utils/erp5diff/ERP5Diff.py

nobody at svn.erp5.org nobody at svn.erp5.org
Mon May 24 17:47:55 CEST 2010


Author: nicolas
Date: Mon May 24 17:47:53 2010
New Revision: 35579

URL: http://svn.erp5.org?rev=35579&view=rev
Log:
Use better algorithm to compare two xml nodes.


Modified:
    erp5/trunk/utils/erp5diff/ERP5Diff.py

Modified: erp5/trunk/utils/erp5diff/ERP5Diff.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5diff/ERP5Diff.py?rev=35579&r1=35578&r2=35579&view=diff
==============================================================================
--- erp5/trunk/utils/erp5diff/ERP5Diff.py [utf8] (original)
+++ erp5/trunk/utils/erp5diff/ERP5Diff.py [utf8] Mon May 24 17:47:53 2010
@@ -40,13 +40,17 @@
 class FileContentNotEqual(Exception):
   pass
 
-def fileComparisonIterator(file1, file2):
-  value1 = file1.next()
-  value2 = file2.next()
-  if value1 == value2:
-    yield value1, value2
-  else:
-    raise FileContentNotEqual
+def isNodeEquals(old, new):
+  if old.tag != new.tag or old.attrib != new.attrib:
+    return False
+  if old.text != new.text or old.tail != new.tail:
+    return False
+  if len(old) != len(new):
+    return False
+  for old_child, new_child in zip(old, new):
+    if not isNodeEquals(old_child, new_child):
+      return False
+  return True
 
 class ERP5Diff:
   """
@@ -481,27 +485,12 @@
     for old_index, old_element in enumerate(old_list):
       if old_element not in old_candidate_list:
         continue
-      old_tree = deepcopy(old_element).getroottree()
-      old_c14n = StringIO()
-      old_tree.write_c14n(old_c14n)
-      old_c14n.seek(0)
       for new_element in new_list:
         new_index = new_list.index(new_element)
         if new_element not in new_candidate_list:
           continue
-        new_tree = deepcopy(new_element).getroottree()
-        new_c14n = StringIO()
-        new_tree.write_c14n(new_c14n)
-        new_c14n.seek(0)
-        file_equality = True
-        try:
-          #Use generator to avoid reading file entirely
-          #Stop iteration at first difference
-          list(fileComparisonIterator(old_c14n, new_c14n))
-        except FileContentNotEqual:
-          file_equality = False
-        old_c14n.seek(0)
-        if file_equality:
+        node_equality = isNodeEquals(old_element, new_element)
+        if node_equality:
           index_key_on_new_tree = new_element.getparent().index(new_element)
           old_new_index_mapping[index_key_on_new_tree] = old_element
           new_start = new_index + 1




More information about the Erp5-report mailing list