[Erp5-report] r30025 - in /erp5/trunk/utils/erp5diff: ERP5Diff.py README

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Oct 27 11:33:29 CET 2009


Author: nicolas
Date: Tue Oct 27 11:33:28 2009
New Revision: 30025

URL: http://svn.erp5.org?rev=30025&view=rev
Log:
Append position in xpath expression when value of id attribute is not unique

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

Modified: erp5/trunk/utils/erp5diff/ERP5Diff.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5diff/ERP5Diff.py?rev=30025&r1=30024&r2=30025&view=diff
==============================================================================
--- erp5/trunk/utils/erp5diff/ERP5Diff.py [utf8] (original)
+++ erp5/trunk/utils/erp5diff/ERP5Diff.py [utf8] Tue Oct 27 11:33:28 2009
@@ -238,10 +238,8 @@
 
     id_list = []
     for attr_map in (element1.attrib, element2.attrib):
-      for name, value in attr_map.items():
-        if name == 'id':
-          id_list.append(value)
-          break
+      if 'id' in attr_map:
+        id_list.append(attr_map['id'])
 
     if len(id_list) == 0:
       return True
@@ -283,7 +281,7 @@
 
   def _checkEmptiness(self, element):
     """
-      Check if an element has child values.
+      Check if an element has Element or Text nodes
     """
     for child in element:
       if type(child) == etree._Element:
@@ -327,7 +325,12 @@
 
       if id_val is not None:
         # If an attribute 'id' is present, uses the attribute for convenience.
-        path_list.append("%s[@id='%s']" % (element.tag, id_val))
+        position_predicate = ''
+        len_all_similar_sibling = len(element.xpath('../*[@id = "%s"]' % id_val))
+        if len_all_similar_sibling > 1:
+          position = len_all_similar_sibling - element.xpath('count(following-sibling::%s[@id = "%s"])' % (element.tag, id_val) ) 
+          position_predicate = '[%i]' % position
+        path_list.append("%s[@id='%s']%s" % (element.tag, id_val, position_predicate,))
         # Increase the count, for a case where other elements with the same tag name do not have
         # 'id' attrib.
         count_map[element.tag] += 1

Modified: erp5/trunk/utils/erp5diff/README
URL: http://svn.erp5.org/erp5/trunk/utils/erp5diff/README?rev=30025&r1=30024&r2=30025&view=diff
==============================================================================
--- erp5/trunk/utils/erp5diff/README [utf8] (original)
+++ erp5/trunk/utils/erp5diff/README [utf8] Tue Oct 27 11:33:28 2009
@@ -145,7 +145,7 @@
     <xupdate:update select="/object[@id='313730']/description">description1 --- $sdfrç_sdfsçdf_oisfsopf</xupdate:update>
     <xupdate:update select="/object[@id='313730']/language/attribute::type">None</xupdate:update>
     <xupdate:update select="/object[@id='313730']/language"/>
-    <xupdate:remove select="/object[@id='313730']/workflow_action[@id='edit_workflow']"/>
+    <xupdate:remove select="/object[@id='313730']/workflow_action[@id='edit_workflow'][2]"/>
   </xupdate:modifications>
 
 5. update two elements includes some symbols 
@@ -208,8 +208,8 @@
   >>> erp5diff.compare(old_xml, new_xml)
   >>> erp5diff.output()
   <xupdate:modifications xmlns:xupdate="http://www.xmldb.org/xupdate" version="1.0">
-    <xupdate:update select="/object[@id='313730']/workflow_action[@id='edit_workflow']/time">2009/08/28 19:12:40.905 GMT+9</xupdate:update>
-    <xupdate:update select="/object[@id='313730']/workflow_action[@id='edit_workflow']/time">2009/08/28 19:12:40.910 GMT+9</xupdate:update>
+    <xupdate:update select="/object[@id='313730']/workflow_action[@id='edit_workflow'][2]/time">2009/08/28 19:12:40.905 GMT+9</xupdate:update>
+    <xupdate:update select="/object[@id='313730']/workflow_action[@id='edit_workflow'][3]/time">2009/08/28 19:12:40.910 GMT+9</xupdate:update>
   </xupdate:modifications>
 
 7. insert and remove elements
@@ -637,9 +637,9 @@
   >>> erp5diff.compare(old_xml, new_xml)
   >>> erp5diff.output()
   <xupdate:modifications xmlns:xupdate="http://www.xmldb.org/xupdate" version="1.0">
-    <xupdate:update select="/object[@id='313730']/workflow_action[2]/time">2009/08/29 19:12:34.432 GMT+9</xupdate:update>
-    <xupdate:update select="/object[@id='313730']/workflow_action[3]/time">2009/08/30 19:12:34.434 GMT+9</xupdate:update>     
-    <xupdate:update select="/object[@id='313730']/workflow_action[4]/time">2009/08/31 19:12:34.436 GMT+9</xupdate:update>   
+    <xupdate:update select="/object[@id='313730']/workflow_action[@id='edit_workflow'][2]/time">2009/08/29 19:12:34.432 GMT+9</xupdate:update>
+    <xupdate:update select="/object[@id='313730']/workflow_action[@id='edit_workflow'][3]/time">2009/08/30 19:12:34.434 GMT+9</xupdate:update>     
+    <xupdate:update select="/object[@id='313730']/workflow_action[@id='edit_workflow'][4]/time">2009/08/31 19:12:34.436 GMT+9</xupdate:update>   
   </xupdate:modifications>
 
 22. Modify attributes of sequencial objects




More information about the Erp5-report mailing list