From: Daan De Meyer Date: Sat, 16 Dec 2023 23:01:56 +0000 (+0100) Subject: opensuse: Use curl to fetch repomd.xml X-Git-Tag: v20~55^2~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=df858f6fcbf10298fa3aa0ded00807077a0e93a6;p=thirdparty%2Fmkosi.git opensuse: Use curl to fetch repomd.xml urllib.request.urlopen() means we're responsible for catching all the exceptions and showing a proper error message to the user. Instead, let's just shell out to curl to fetch the file which can translate any errors into user friendly error messages for us. --- diff --git a/mkosi/distributions/opensuse.py b/mkosi/distributions/opensuse.py index cad67dc34..bae8fbea0 100644 --- a/mkosi/distributions/opensuse.py +++ b/mkosi/distributions/opensuse.py @@ -1,9 +1,10 @@ # SPDX-License-Identifier: LGPL-2.1+ import shutil -import urllib.request +import tempfile import xml.etree.ElementTree as ElementTree from collections.abc import Sequence +from pathlib import Path from mkosi.config import Architecture from mkosi.distributions import Distribution, DistributionInstaller, PackageType @@ -11,6 +12,7 @@ from mkosi.installer.dnf import invoke_dnf, setup_dnf from mkosi.installer.rpm import RpmRepository from mkosi.installer.zypper import invoke_zypper, setup_zypper from mkosi.log import die +from mkosi.run import run from mkosi.state import MkosiState @@ -119,17 +121,27 @@ class Installer(DistributionInstaller): def fetch_gpgurls(repourl: str) -> tuple[str, ...]: gpgurls = [f"{repourl}/repodata/repomd.xml.key"] - with urllib.request.urlopen(f"{repourl}/repodata/repomd.xml") as f: - xml = f.read().decode() - root = ElementTree.fromstring(xml) - - tags = root.find("{http://linux.duke.edu/metadata/repo}tags") - if not tags: - die("repomd.xml missing element") - - for child in tags.iter("{http://linux.duke.edu/metadata/repo}content"): - if child.text and child.text.startswith("gpg-pubkey"): - gpgkey = child.text.partition("?")[0] - gpgurls += [f"{repourl}{gpgkey}"] + with tempfile.TemporaryDirectory() as d: + run([ + "curl", + "--location", + "--output-dir", d, + "--remote-name", + "--no-progress-meter", + "--fail", + f"{repourl}/repodata/repomd.xml", + ]) + xml = (Path(d) / "repomd.xml").read_text() + + root = ElementTree.fromstring(xml) + + tags = root.find("{http://linux.duke.edu/metadata/repo}tags") + if not tags: + die("repomd.xml missing element") + + for child in tags.iter("{http://linux.duke.edu/metadata/repo}content"): + if child.text and child.text.startswith("gpg-pubkey"): + gpgkey = child.text.partition("?")[0] + gpgurls += [f"{repourl}{gpgkey}"] return tuple(gpgurls)