pungi: Handle missing SRPM

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ář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2016-12-05 09:18:25 +01:00
parent 83428a06bf
commit 56147f2e4d
2 changed files with 37 additions and 21 deletions

View File

@ -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)
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
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

View File

@ -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.+",