arch: Move exclu(de|sive)arch check to a function

Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2017-06-06 15:25:04 +02:00
parent 3601d6d1a8
commit 700106facf
4 changed files with 37 additions and 13 deletions

View File

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

View File

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

View File

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

View File

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