# 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
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
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 <tags> 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 <tags> 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)