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