fwupd/contrib/generate-metainfo.py
Richard Hughes e1e8b9e261 Only include the last 5 releases in the installed metainfo file
We have to include the entire history in git, and also to generate the NEWS
file, but this reduces the size of the on-disk file by 116Kb.
2022-09-30 12:48:07 +01:00

35 lines
922 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 argparse
import xml.etree.ElementTree as ET
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"-r",
"--releases",
type=int,
default=5,
)
parser.add_argument(
"filename_src", action="store", type=str, help="metainfo source"
)
parser.add_argument(
"filename_dst", action="store", type=str, help="metainfo destination"
)
args = parser.parse_args()
tree = ET.parse(args.filename_src)
root = tree.getroot().findall("releases")[0]
for release in root.findall("release")[args.releases :]:
root.remove(release)
with open(args.filename_dst, "wb") as f:
tree.write(f, encoding="UTF-8", xml_declaration=True)