2012-11-12 14:59:02 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; version 2 of the License.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Library General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2016-09-21 12:49:13 +00:00
|
|
|
# along with this program; if not, see <https://gnu.org/licenses/>.
|
2012-11-12 14:59:02 +00:00
|
|
|
|
2017-03-21 04:32:53 +00:00
|
|
|
from .arch_utils import arches as ALL_ARCHES
|
|
|
|
from .arch_utils import getBaseArch, getMultiArchInfo, getArchList
|
2012-11-12 14:59:02 +00:00
|
|
|
|
|
|
|
TREE_ARCH_YUM_ARCH_MAP = {
|
|
|
|
"i386": "athlon",
|
|
|
|
"ppc64": "ppc64p7",
|
|
|
|
"sparc": "sparc64v",
|
|
|
|
"arm": "armv7l",
|
|
|
|
"armhfp": "armv7hnl",
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def tree_arch_to_yum_arch(tree_arch):
|
2017-03-21 04:32:53 +00:00
|
|
|
# this is basically an opposite to pungi.arch_utils.getBaseArch()
|
2012-11-12 14:59:02 +00:00
|
|
|
yum_arch = TREE_ARCH_YUM_ARCH_MAP.get(tree_arch, tree_arch)
|
|
|
|
return yum_arch
|
|
|
|
|
|
|
|
|
|
|
|
def get_multilib_arch(yum_arch):
|
2017-03-21 04:32:53 +00:00
|
|
|
arch_info = getMultiArchInfo(yum_arch)
|
2012-11-12 14:59:02 +00:00
|
|
|
if arch_info is None:
|
|
|
|
return None
|
|
|
|
return arch_info[0]
|
|
|
|
|
|
|
|
|
|
|
|
def get_valid_multilib_arches(tree_arch):
|
|
|
|
yum_arch = tree_arch_to_yum_arch(tree_arch)
|
|
|
|
multilib_arch = get_multilib_arch(yum_arch)
|
|
|
|
if not multilib_arch:
|
|
|
|
return []
|
2017-03-21 04:32:53 +00:00
|
|
|
return [i for i in getArchList(multilib_arch) if i not in ("noarch", "src")]
|
2012-11-12 14:59:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_valid_arches(tree_arch, multilib=True, add_noarch=True, add_src=False):
|
|
|
|
result = []
|
|
|
|
|
|
|
|
yum_arch = tree_arch_to_yum_arch(tree_arch)
|
2017-03-21 04:32:53 +00:00
|
|
|
for arch in getArchList(yum_arch):
|
2012-11-12 14:59:02 +00:00
|
|
|
if arch not in result:
|
|
|
|
result.append(arch)
|
|
|
|
|
|
|
|
if not multilib:
|
|
|
|
for i in get_valid_multilib_arches(tree_arch):
|
|
|
|
while i in result:
|
|
|
|
result.remove(i)
|
|
|
|
|
|
|
|
if add_noarch and "noarch" not in result:
|
|
|
|
result.append("noarch")
|
|
|
|
|
|
|
|
if add_src and "src" not in result:
|
|
|
|
result.append("src")
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
def get_compatible_arches(arch, multilib=False):
|
2017-03-21 04:32:53 +00:00
|
|
|
tree_arch = getBaseArch(arch)
|
2012-11-12 14:59:02 +00:00
|
|
|
compatible_arches = get_valid_arches(tree_arch, multilib=multilib)
|
|
|
|
return compatible_arches
|
|
|
|
|
|
|
|
|
|
|
|
def is_valid_arch(arch):
|
|
|
|
if arch in ("noarch", "src", "nosrc"):
|
|
|
|
return True
|
2017-03-21 04:32:53 +00:00
|
|
|
if arch in ALL_ARCHES:
|
2012-11-12 14:59:02 +00:00
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
def split_name_arch(name_arch):
|
|
|
|
if "." in name_arch:
|
|
|
|
name, arch = name_arch.rsplit(".", 1)
|
|
|
|
if not is_valid_arch(arch):
|
|
|
|
name, arch = name_arch, None
|
|
|
|
else:
|
|
|
|
name, arch = name_arch, None
|
|
|
|
return name, arch
|
2017-06-06 13:25:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
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
|