[Formed-commits] r394 - trunk/contrib

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Aug 12 12:00:48 CEST 2010


Author: torsten
Date: 2010-08-12 12:00:47 +0200 (Thu, 12 Aug 2010)
New Revision: 394

Modified:
   trunk/contrib/diff_formed.py
Log:
Improved script. Added more options


Modified: trunk/contrib/diff_formed.py
===================================================================
--- trunk/contrib/diff_formed.py	2010-08-10 15:53:42 UTC (rev 393)
+++ trunk/contrib/diff_formed.py	2010-08-12 10:00:47 UTC (rev 394)
@@ -72,16 +72,31 @@
             if f2 is not None:
                 f2.close()
 
-    def perform(self, elements=None, check_attributes=False):
-        log.info('Only checking %s elements' % ",".join(elements))
+    def perform(self, elements=None, subtree=None, fields=None, check_attributes=False):
+        log.info('Only checking %s elements' % ",".join(elements or ['all']))
         for element in self.elements:
             if elements is not None:
                 if element not in elements: continue 
             self.elements_old[element] = []
             self.elements_new[element] = []
-            for e in self.old_xml_doc.findall("//%s" % element):
+            if subtree:
+                needle = '//*[@name="%s"]//%s' % (subtree, element)
+            else:
+                needle = '//%s' % (element)
+            log.debug("Searching for %s" % needle)
+            for e in self.old_xml_doc.findall(needle):
+                if fields is not None:
+                    name = e.attrib.get('name')
+                    if str(name ) not in fields: 
+                        log.debug('Old: Not found %s in %s' % (name, fields))
+                        continue
                 self.elements_old[element].append(e)
-            for e in self.new_xml_doc.findall("//%s" % element):
+            for e in self.new_xml_doc.findall(needle):
+                if fields is not None:
+                    name = e.attrib.get('name')
+                    if str(name )not in fields: 
+                        log.debug('New: Not found %s in %s' % (name, fields))
+                        continue
                 self.elements_new[element].append(e)
             self.diff_element(element, check_attributes)
 
@@ -128,6 +143,8 @@
                     break
             if not found:
                     error.append("New")
+                    if element == 'choice':
+                        error.extend(self.diff_choicelist(None, o, check_attributes))
 
             if error:
                 out.append("Field: %s (%s)" % (name, element))
@@ -144,10 +161,12 @@
         old = {}
         new = {}
         errors = []
-        for c in o.getchildren():
-            old[c.attrib.get('value')] = c
-        for c in n.getchildren():
-            new[c.attrib.get('value')] = c
+        if o is not None:
+            for c in o.findall('.//bool'):
+                old[c.attrib.get('value')] = c
+        if n is not None:
+            for c in n.findall('.//bool'):
+                new[c.attrib.get('value')] = c
 
         for key in old.keys():
             if new.has_key(key):
@@ -192,13 +211,15 @@
 
 def main():
     try:
-        opts, args = getopt.getopt(sys.argv[1:], 'hvVe:',
-        ['elements=', 'check-attributes'])
+        opts, args = getopt.getopt(sys.argv[1:], 'hvVe:s:f:',
+        ['elements=', 'check-attributes', 'subtree=', 'fields='])
    
     except getopt.error, msg:
         usage(1, msg)
     
     elements = None
+    subtree = None
+    fields = None
     check_attributes = False
     for opt, arg in opts:
         if opt in ('-v'):
@@ -210,13 +231,19 @@
         if opt in ('-e', '--elements'):
             elements = arg.split(',')
             log.debug('Elements: %s' % elements)
+        if opt in ('-s', '--subtree'):
+            subtree = arg
+            log.debug('Subtree: %s' % subtree)
+        if opt in ('-f', '--fields'):
+            fields = arg.split(',')
+            log.debug('Fields: %s' % fields)
         if opt in ('--check-attributes'):
             check_attributes = True
     if len(args) < 2:
         usage(1)
 
     ins = Inspector(args[0], args[1])
-    ins.perform(elements, check_attributes)
+    ins.perform(elements, subtree, fields, check_attributes)
 
 if __name__ == '__main__':
     main()



More information about the Formed-commits mailing list