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