josephxsxn

SiteXML Compare Script

Mar 13th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.17 KB | None | 0 0
  1. import sys
  2. import xml.etree.ElementTree as ET
  3.  
  4.  
  5. tree1 = ET.parse(sys.argv[1])
  6. tree2 = ET.parse(sys.argv[2])
  7. root1 = tree1.getroot()
  8. root2 = tree2.getroot()
  9.  
  10. dic1 = {}
  11. dic2 = {}
  12.  
  13. for configprop in root1.findall('property'):
  14.         name = configprop.find('name')
  15.         val = configprop.find('value')
  16.         dic1[name.text] = val.text
  17.         #print name.text, val.text
  18.  
  19. for configprop in root2.findall('property'):
  20.         name = configprop.find('name')
  21.         val = configprop.find('value')
  22.         dic2[name.text] = val.text
  23.  
  24. print ('##Checking Values')
  25. for entry in dic1:
  26.         try :
  27.                 if dic2[entry] == dic1[entry] :
  28.                         continue
  29.                 else :
  30.                         print('DIFF         ' + entry + ' Source: ' + dic1[entry] + ' Target: ' + dic2[entry])
  31.         except:
  32.                 print('MISS[TARGET] ' + entry + 'Source: ' + dic1[entry] + ' Target: NONE ')
  33.                 continue
  34.  
  35.  
  36. dic1keys = set(dic1.keys())
  37. dic2keys = set(dic2.keys())
  38.  
  39. missingSourceKeys = dic2keys.difference(dic1keys)
  40.  
  41. for key in missingSourceKeys:
  42.         print('MISS[SOURCE] ' + key + 'Source: NONE ' + 'Target: ' + dic2[key])
Advertisement
Add Comment
Please, Sign In to add comment