Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1 | #! /usr/bin/env python3 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2 | |
| 3 | import sys |
| 4 | try: |
| 5 | import xml.etree.cElementTree as etree |
| 6 | except: |
| 7 | import xml.etree.ElementTree as etree |
| 8 | |
| 9 | def child (elem, name): |
| 10 | for e in elem.getchildren(): |
| 11 | if e.tag == name: |
| 12 | return e |
| 13 | return None |
| 14 | |
| 15 | def children (elem, name=None): |
| 16 | l = elem.getchildren() |
| 17 | if name: |
| 18 | l = [e for e in l if e.tag == name] |
| 19 | return l |
| 20 | |
| 21 | xml = etree.parse(sys.argv[1]) |
| 22 | |
| 23 | for schema in child(xml.getroot(), "schemalist").getchildren(): |
| 24 | e = child(schema, "short") |
| 25 | if e is not None: |
| 26 | schema.remove(e) |
| 27 | |
| 28 | e = child(schema, "long") |
| 29 | if e is not None: |
| 30 | schema.remove(e) |
| 31 | |
| 32 | for locale in children(schema, "locale"): |
| 33 | # One locale must exist so leave C locale... |
| 34 | a = locale.attrib.get("name") |
| 35 | if a == 'C': |
| 36 | continue |
| 37 | e = child(locale, "default") |
| 38 | if e is None: |
| 39 | schema.remove(locale) |
| 40 | else: |
| 41 | e = child(locale, "short") |
| 42 | if e is not None: |
| 43 | locale.remove(e) |
| 44 | e = child(locale, "long") |
| 45 | if e is not None: |
| 46 | locale.remove(e) |
| 47 | |
| 48 | xml.write(sys.stdout, "UTF-8") |
| 49 | |