forked from openbmc/openbmc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oe-trim-schemas
executable file
·49 lines (40 loc) · 1.13 KB
/
oe-trim-schemas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#! /usr/bin/env python
import sys
try:
import xml.etree.cElementTree as etree
except:
import xml.etree.ElementTree as etree
def child (elem, name):
for e in elem.getchildren():
if e.tag == name:
return e
return None
def children (elem, name=None):
l = elem.getchildren()
if name:
l = [e for e in l if e.tag == name]
return l
xml = etree.parse(sys.argv[1])
for schema in child(xml.getroot(), "schemalist").getchildren():
e = child(schema, "short")
if e is not None:
schema.remove(e)
e = child(schema, "long")
if e is not None:
schema.remove(e)
for locale in children(schema, "locale"):
# One locale must exist so leave C locale...
a = locale.attrib.get("name")
if a == 'C':
continue
e = child(locale, "default")
if e is None:
schema.remove(locale)
else:
e = child(locale, "short")
if e is not None:
locale.remove(e)
e = child(locale, "long")
if e is not None:
locale.remove(e)
xml.write(sys.stdout, "UTF-8")