From 56147f2e4d2bc5aa044924a6374008b8cde69d1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Mon, 5 Dec 2016 09:18:25 +0100 Subject: [PATCH] pungi: Handle missing SRPM MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Source packages can be excluded while binary packages should still go into the compose. This patch makes it so that the mapping from binary packages to source packages contains None in such case. The code is already capable of handling that. A warning will be emitted for each binary package without source. This also allows us to remove some code from `createSourceHashes` that is now unused. A test for excluding source package is added as well. Signed-off-by: Lubomír Sedlář --- pungi/gather.py | 28 +++++++--------------------- tests/test_pungi.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/pungi/gather.py b/pungi/gather.py index b08c59d9..fe3ddd7a 100644 --- a/pungi/gather.py +++ b/pungi/gather.py @@ -20,7 +20,6 @@ import re import shutil import sys import pungi.util -import pprint import lockfile import logging import urlgrabber.progress @@ -1007,9 +1006,11 @@ class Pungi(PungiBase): # ... but even "nosrc" packages are stored as "src" in repodata srpm_po_list = self.ayum.pkgSack.searchNevra(name=name, ver=ver, rel=rel, arch="src") srpm_po_list = self.excludePackages(srpm_po_list) - if not srpm_po_list: - raise RuntimeError("Cannot find a source rpm for %s" % po.sourcerpm) - srpm_po = srpm_po_list[0] + try: + srpm_po = srpm_po_list[0] + except IndexError: + self.logger.warning("Cannot find a source rpm for %s" % po.sourcerpm) + srpm_po = None self.sourcerpm_srpmpo_map[po.sourcerpm] = srpm_po return srpm_po @@ -1020,28 +1021,13 @@ class Pungi(PungiBase): self.src_by_bin = {} self.bin_by_src = {} self.logger.info("Generating source <-> binary package mappings") - #(dummy1, everything, dummy2) = yum.packages.parsePackages(self.all_pkgs, ['*'], pkgdict=self.pkg_refs.copy()) - failed = [] for po in self.all_pkgs: if is_source(po): continue - try: - srpmpo = self.get_srpm_po(po) - except RuntimeError: - failed.append(po.sourcerpm) - continue + srpmpo = self.get_srpm_po(po) self.src_by_bin[po] = srpmpo - if self.bin_by_src.has_key(srpmpo): - self.bin_by_src[srpmpo].append(po) - else: - self.bin_by_src[srpmpo] = [po] - - if failed: - self.logger.info("The following srpms could not be found: %s" % ( - pprint.pformat(list(sorted(failed))))) - self.logger.info("Couldn't find %i of %i srpms." % ( - len(failed), len(self.src_by_bin))) + self.bin_by_src.setdefault(srpmpo, []).append(po) def add_srpms(self, po_list=None): """Cycle through the list of package objects and diff --git a/tests/test_pungi.py b/tests/test_pungi.py index 60f2fc3c..5feba67c 100644 --- a/tests/test_pungi.py +++ b/tests/test_pungi.py @@ -741,6 +741,36 @@ class TestPungi(unittest.TestCase): "dummy-glibc-debuginfo-common-2.14-5.x86_64.rpm", ]) + def test_bash_multilib_exclude_source(self): + packages = [ + "dummy-bash.+", + "-dummy-bash.src", + ] + pkg_map = self.go(packages, None, greedy="none") + + self.assertNotIn("dummy-bash-4.2.37-6.src.rpm", pkg_map["srpm"]) + + self.assertItemsEqual(pkg_map["rpm"], [ + "dummy-basesystem-10.0-6.noarch.rpm", + "dummy-bash-4.2.37-6.i686.rpm", + "dummy-filesystem-4.2.37-6.x86_64.rpm", + "dummy-glibc-2.14-5.i686.rpm", + "dummy-glibc-2.14-5.x86_64.rpm", + "dummy-glibc-common-2.14-5.x86_64.rpm", + ]) + self.assertItemsEqual(pkg_map["srpm"], [ + "dummy-basesystem-10.0-6.src.rpm", + "dummy-filesystem-4.2.37-6.src.rpm", + "dummy-glibc-2.14-5.src.rpm", + ]) + self.assertItemsEqual(pkg_map["debuginfo"], [ + "dummy-bash-debuginfo-4.2.37-6.i686.rpm", + "dummy-glibc-debuginfo-2.14-5.i686.rpm", + "dummy-glibc-debuginfo-2.14-5.x86_64.rpm", + "dummy-glibc-debuginfo-common-2.14-5.i686.rpm", + "dummy-glibc-debuginfo-common-2.14-5.x86_64.rpm", + ]) + def test_bash_multilib_greedy(self): packages = [ "dummy-bash.+",