blob: 7c199ef1df2dfc1accfab1f3afa4036c2cd1e356 [file] [log] [blame]
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001#! /usr/bin/env python3
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002
3import sys
4try:
5 import xml.etree.cElementTree as etree
6except:
7 import xml.etree.ElementTree as etree
8
9def child (elem, name):
10 for e in elem.getchildren():
11 if e.tag == name:
12 return e
13 return None
14
15def 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
Brad Bishop6e60e8b2018-02-01 10:27:11 -050021if len(sys.argv) < 2 or sys.argv[1] in ('-h', '--help'):
22 print('oe-trim-schemas: error: the following arguments are required: schema\n'
23 'Usage: oe-trim-schemas schema\n\n'
24 'OpenEmbedded trim schemas - remove unneeded schema locale translations\n'
25 ' from gconf schema files\n\n'
26 'arguments:\n'
27 ' schema gconf schema file to trim\n')
28 sys.exit(2)
29
Patrick Williamsc124f4f2015-09-15 14:41:29 -050030xml = etree.parse(sys.argv[1])
31
32for schema in child(xml.getroot(), "schemalist").getchildren():
33 e = child(schema, "short")
34 if e is not None:
35 schema.remove(e)
36
37 e = child(schema, "long")
38 if e is not None:
39 schema.remove(e)
40
41 for locale in children(schema, "locale"):
42 # One locale must exist so leave C locale...
43 a = locale.attrib.get("name")
44 if a == 'C':
45 continue
46 e = child(locale, "default")
47 if e is None:
48 schema.remove(locale)
49 else:
50 e = child(locale, "short")
51 if e is not None:
52 locale.remove(e)
53 e = child(locale, "long")
54 if e is not None:
55 locale.remove(e)
56
57xml.write(sys.stdout, "UTF-8")
58