9b97a2ea88
there are no remaining users of sorted option lists except the docbook build, which sorts its input separately.
28 lines
689 B
Python
28 lines
689 B
Python
import xml.etree.ElementTree as ET
|
|
import sys
|
|
|
|
tree = ET.parse(sys.argv[1])
|
|
# the xml tree is of the form
|
|
# <expr><list> {all options, each an attrs} </list></expr>
|
|
options = list(tree.getroot().find('list'))
|
|
|
|
def sortKey(opt):
|
|
def order(s):
|
|
if s.startswith("enable"):
|
|
return 0
|
|
if s.startswith("package"):
|
|
return 1
|
|
return 2
|
|
|
|
return [
|
|
(order(p.attrib['value']), p.attrib['value'])
|
|
for p in opt.findall('attr[@name="loc"]/list/string')
|
|
]
|
|
|
|
options.sort(key=sortKey)
|
|
|
|
doc = ET.Element("expr")
|
|
newOptions = ET.SubElement(doc, "list")
|
|
newOptions.extend(options)
|
|
ET.ElementTree(doc).write(sys.argv[2], encoding='utf-8')
|