fwupd/contrib/generate-gresource-xml.py
Khem Raj e9964a0f96 trivial: Fix compile when using python 3.7 or older
Signed-off-by: Richard Hughes <richard@hughsie.com>
2022-09-20 16:05:13 +01:00

32 lines
856 B
Python
Executable File

#!/usr/bin/python3
# pylint: disable=invalid-name,missing-docstring
#
# Copyright (C) 2022 Richard Hughes <richard@hughsie.com>
#
# SPDX-License-Identifier: LGPL-2.1+
import sys
import os
import xml.etree.ElementTree as ET
if len(sys.argv) < 2:
print("not enough arguments")
sys.exit(1)
root = ET.Element("gresources")
n_gresource = ET.SubElement(root, "gresource", {"prefix": "/org/freedesktop/fwupd"})
for fn in sorted(sys.argv[2:]):
n_file = ET.SubElement(n_gresource, "file", {"compressed": "true"})
n_file.text = fn
if fn.endswith(".xml"):
n_file.set("preprocess", "xml-stripblanks")
n_file.set("alias", os.path.basename(fn))
with open(sys.argv[1], "wb") as f:
try:
f.write(ET.tostring(root, "utf-8", xml_declaration=True))
except TypeError:
f.write(ET.tostring(root, "utf-8"))
sys.exit(0)