at 23.05-pre 689 B view raw
1import xml.etree.ElementTree as ET 2import sys 3 4tree = ET.parse(sys.argv[1]) 5# the xml tree is of the form 6# <expr><list> {all options, each an attrs} </list></expr> 7options = list(tree.getroot().find('list')) 8 9def sortKey(opt): 10 def order(s): 11 if s.startswith("enable"): 12 return 0 13 if s.startswith("package"): 14 return 1 15 return 2 16 17 return [ 18 (order(p.attrib['value']), p.attrib['value']) 19 for p in opt.findall('attr[@name="loc"]/list/string') 20 ] 21 22options.sort(key=sortKey) 23 24doc = ET.Element("expr") 25newOptions = ET.SubElement(doc, "list") 26newOptions.extend(options) 27ET.ElementTree(doc).write(sys.argv[2], encoding='utf-8')