From 700106facf882f5876a4437440b1713b5de7955a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Tue, 6 Jun 2017 15:25:04 +0200 Subject: [PATCH] arch: Move exclu(de|sive)arch check to a function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lubomír Sedlář --- pungi/arch.py | 15 +++++++++++++++ pungi/phases/gather/sources/source_module.py | 6 +----- pungi/phases/pkgset/pkgsets.py | 10 ++-------- tests/test_arch.py | 19 +++++++++++++++++++ 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/pungi/arch.py b/pungi/arch.py index 8cc3d52e..e24afdcb 100644 --- a/pungi/arch.py +++ b/pungi/arch.py @@ -91,3 +91,18 @@ def split_name_arch(name_arch): else: name, arch = name_arch, None return name, arch + + +def is_excluded(package, arches, logger=None): + """Check if package is excluded from given architectures.""" + if (package.excludearch and set(package.excludearch) & set(arches)): + if logger: + logger.debug("Excluding (EXCLUDEARCH: %s): %s" + % (sorted(set(package.excludearch)), package.file_name)) + return True + if (package.exclusivearch and not (set(package.exclusivearch) & set(arches))): + if logger: + logger.debug("Excluding (EXCLUSIVEARCH: %s): %s" + % (sorted(set(package.exclusivearch)), package.file_name)) + return True + return False diff --git a/pungi/phases/gather/sources/source_module.py b/pungi/phases/gather/sources/source_module.py index 41510ee8..cf6cbe98 100644 --- a/pungi/phases/gather/sources/source_module.py +++ b/pungi/phases/gather/sources/source_module.py @@ -48,11 +48,7 @@ class GatherSourceModule(pungi.phases.gather.source.GatherSourceBase): for rpm_obj in rpms: # Skip the RPM if it is excluded on this arch or exclusive # for different arch. - if (rpm_obj.excludearch and - set(rpm_obj.excludearch) & set(compatible_arches)): - continue - if (rpm_obj.exclusivearch and not - (set(rpm_obj.exclusivearch) & set(compatible_arches))): + if pungi.arch.is_excluded(rpm_obj, compatible_arches): continue for mmd in variant.mmds: diff --git a/pungi/phases/pkgset/pkgsets.py b/pungi/phases/pkgset/pkgsets.py index 03c6e458..331a33bc 100644 --- a/pungi/phases/pkgset/pkgsets.py +++ b/pungi/phases/pkgset/pkgsets.py @@ -30,7 +30,7 @@ from kobo.threads import WorkerThread, ThreadPool import pungi.wrappers.kojiwrapper from pungi.util import pkg_is_srpm -from pungi.arch import get_valid_arches +from pungi.arch import get_valid_arches, is_excluded class ReaderPool(ThreadPool): @@ -160,13 +160,7 @@ class PackageSetBase(kobo.log.LoggingBase): # TODO: test if it really works continue if exclusivearch_list and arch == "noarch": - if i.excludearch and set(i.excludearch) & set(exclusivearch_list): - self.log_debug("Excluding (EXCLUDEARCH: %s): %s" - % (sorted(set(i.excludearch)), i.file_name)) - continue - if i.exclusivearch and not (set(i.exclusivearch) & set(exclusivearch_list)): - self.log_debug("Excluding (EXCLUSIVEARCH: %s): %s" - % (sorted(set(i.exclusivearch)), i.file_name)) + if is_excluded(i, exclusivearch_list, logger=self._logger): continue if arch in ("nosrc", "src"): diff --git a/tests/test_arch.py b/tests/test_arch.py index d4170b50..c5edd818 100644 --- a/tests/test_arch.py +++ b/tests/test_arch.py @@ -118,5 +118,24 @@ class TestArch(unittest.TestCase): self.assertEqual(get_valid_multilib_arches("x86_64"), ['athlon', 'i686', 'i586', 'i486', 'i386']) +class TestExclusiveExcludeArch(unittest.TestCase): + def test_no_exclude(self): + pkg = mock.Mock(excludearch=[], exclusivearch=[], file_name='pkg.rpm') + self.assertFalse(is_excluded(pkg, ['x86_64'])) + + def test_exclude_arch(self): + log = mock.Mock() + pkg = mock.Mock(excludearch=['x86_64'], exclusivearch=[], file_name='pkg.rpm') + self.assertTrue(is_excluded(pkg, ['x86_64'], logger=log)) + self.assertEqual(log.mock_calls, + [mock.call.debug("Excluding (EXCLUDEARCH: ['x86_64']): pkg.rpm")]) + + def test_exclusive_arch(self): + log = mock.Mock() + pkg = mock.Mock(excludearch=[], exclusivearch=['aarch64'], file_name='pkg.rpm') + self.assertTrue(is_excluded(pkg, ['x86_64'], logger=log)) + self.assertEqual(log.mock_calls, + [mock.call.debug("Excluding (EXCLUSIVEARCH: ['aarch64']): pkg.rpm")]) + if __name__ == "__main__": unittest.main()