From 2ba797a18ca1cc480e97627356f683ea9aae6a69 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 6 Jan 2025 16:38:43 +0100 Subject: [PATCH] sources: tweak fetch_all and fix pylint error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit fixes the pylint errors and as a drive-by tweaks some naming in `fetch_all()`. Maybe they became a bit verbose along the way, idk. Thanks also to Tomáš Hozza for the dict.setdefault() suggestion. --- sources/org.osbuild.librepo | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/sources/org.osbuild.librepo b/sources/org.osbuild.librepo index f1382909..474a203e 100755 --- a/sources/org.osbuild.librepo +++ b/sources/org.osbuild.librepo @@ -189,22 +189,19 @@ class LibRepoSource(sources.SourceService): cbdata=path, endcb=self._endcb) + # pylint: disable=too-many-branches def fetch_all(self, items: Dict) -> None: """Use librepo to download the packages""" # Organize the packages by the mirror id - packages = dict() - for id, pkg in items.items(): + packages_from_mirror = {} + for item_id, pkg in items.items(): if pkg["mirror"] not in self.options["mirrors"]: raise RuntimeError(f'Missing mirror: {pkg["mirror"]}') - - if pkg["mirror"] not in packages: - packages[pkg["mirror"]] = [(pkg["path"], id)] - else: - packages[pkg["mirror"]].append((pkg["path"], id)) + packages_from_mirror.setdefault(pkg["mirror"], []).append((pkg["path"], item_id)) # Download packages from each of the mirror ids - for m in packages: - mirror = self.options["mirrors"][m] + for mirror_id, packages in packages_from_mirror.items(): + mirror = self.options["mirrors"][mirror_id] handle = librepo.Handle() handle.repotype = librepo.YUMREPO if mirror["type"] == "metalink": @@ -234,7 +231,7 @@ class LibRepoSource(sources.SourceService): self._setup_rhsm(handle, mirror) download = [] - for path, checksum in packages[m]: + for path, checksum in packages: download.append(self.make_pkg_target(handle, f"{self.cache}/{checksum}", path, checksum)) # Download everything from this mirror