python3Packages.xknx: 1.1.0 -> 1.2.0
[NixPkgs.git] / nixos / lib / make-options-doc / sortXML.py
blobe63ff3538b3fe9edfcd2866c2b5724c4ba483b06
1 import xml.etree.ElementTree as ET
2 import sys
4 tree = ET.parse(sys.argv[1])
5 # the xml tree is of the form
6 # <expr><list> {all options, each an attrs} </list></expr>
7 options = list(tree.getroot().find('list'))
9 def 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
17 return [
18 (order(p.attrib['value']), p.attrib['value'])
19 for p in opt.findall('attr[@name="loc"]/list/string')
22 options.sort(key=sortKey)
24 doc = ET.Element("expr")
25 newOptions = ET.SubElement(doc, "list")
26 newOptions.extend(options)
27 ET.ElementTree(doc).write(sys.argv[2], encoding='utf-8')