poky/scripts/oe-trim-schemas
Ed Bartosh cdff6bc0c1 scripts: python3: change python to python3 in shebang
(From OE-Core rev: 4b544ff388497cac82b0585f237900595523e1cb)

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2016-06-03 13:13:29 +01:00

50 lines
1.1 KiB
Python
Executable File

#! /usr/bin/env python3
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")