From a11a80531f87cd238a759136cdd279989db63e3d Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Wed, 29 Jun 2022 15:36:34 -0400 Subject: [PATCH] Add ELN-Extras group ELN-Extras will be automatically added to the comps.xml when `make comps-eln.xml` is run. Signed-off-by: Stephen Gallagher --- .gitignore | 3 + Makefile | 4 ++ comps-eln.xml.in => comps-eln.xml.in.in | 0 update-eln-extras-comps | 75 +++++++++++++++++++++++++ 4 files changed, 82 insertions(+) rename comps-eln.xml.in => comps-eln.xml.in.in (100%) create mode 100755 update-eln-extras-comps diff --git a/.gitignore b/.gitignore index b878e882..87782793 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ /*.xml + +# Automatically generated from comps-eln.xml.in.in +/comps-eln.xml.in diff --git a/Makefile b/Makefile index 65706161..915453c1 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,10 @@ sort: RES=$$(($$RES + $$?)); \ done; exit $$RES +.PHONY: comps-eln.xml.in +comps-eln.xml.in: comps-eln.xml.in.in + ./update-eln-extras-comps comps-eln.xml.in.in comps-eln.xml.in + %.xml: %.xml.in @xmllint --noout $< @if test ".$(CLEANUP)" == .yes; then xsltproc --novalid -o $< comps-cleanup.xsl $<; fi diff --git a/comps-eln.xml.in b/comps-eln.xml.in.in similarity index 100% rename from comps-eln.xml.in rename to comps-eln.xml.in.in diff --git a/update-eln-extras-comps b/update-eln-extras-comps new file mode 100755 index 00000000..4f2447ae --- /dev/null +++ b/update-eln-extras-comps @@ -0,0 +1,75 @@ +#!/usr/bin/python3 + +import click +import requests +from collections import OrderedDict, defaultdict +from os import path +import xmltodict + +DEFAULT_CONTENT_RESOLVER_URL = "https://tiny.distro.builders" +DEFAULT_CONTENT_RESOLVER_VIEW = "eln-extras" + + +@click.command() +@click.option( + "--content-resolver-url", + "-u", + default=DEFAULT_CONTENT_RESOLVER_URL, + show_default=True, +) +@click.option( + "--content-resolver-view", + "-w", + default=DEFAULT_CONTENT_RESOLVER_VIEW, + show_default=True, +) +@click.argument("infile", type=click.File(mode="rb")) +@click.argument("outfile", type=click.File(mode="wb", atomic=True)) +def cli(content_resolver_url, content_resolver_view, infile, outfile): + comps = xmltodict.parse(infile) + + comps_group = OrderedDict() + comps_group["id"] = "eln-extras" + comps_group["_name"] = "ELN Extras" + comps_group[ + "_description" + ] = "Extra packages not in ELN, but needed to be built like ELN for testing" + comps_group["default"] = "false" + comps_group["uservisible"] = "false" + comps_group["packagelist"] = OrderedDict() + comps_group["packagelist"]["packagereq"] = list() + + ARCHES = ["aarch64", "ppc64le", "s390x", "x86_64"] + package_arches = defaultdict(set) + for arch in ARCHES: + r = requests.get( + f"{content_resolver_url}/view-all-binary-package-name-list--view-{content_resolver_view}--{arch}.txt" + ) + r.raise_for_status() + packages = r.text.split("\n") + + for package in packages: + package_arches[package].add(arch) + + for package in sorted(package_arches.keys()): + entry = OrderedDict() + entry["@variant"] = "Extras" + entry["@arch"] = ",".join(package_arches[package]) + entry["#text"] = package + comps_group["packagelist"]["packagereq"].append(entry) + + comps["comps"]["group"].append(comps_group) + + raw_xml = xmltodict.unparse( + comps, full_document=True, pretty=True, indent=" " + ) + xml = raw_xml.replace( + '', + '', + 1, + ) + outfile.write(xml.encode("UTF-8")) + + +if __name__ == "__main__": + cli()