]>
Commit | Line | Data |
---|---|---|
4b544ff3 | 1 | #! /usr/bin/env python3 |
d5341fb7 RP |
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 | ||
a9fac121 EB |
21 | if 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 | ||
d5341fb7 RP |
30 | xml = etree.parse(sys.argv[1]) |
31 | ||
32 | for 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 | ||
57 | xml.write(sys.stdout, "UTF-8") | |
58 |