2015-06-25 12:37:23 +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.
|
|
|
|
#
|
2016-12-15 09:09:28 +00:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, see <https://gnu.org/licenses/>.
|
2015-06-25 12:37:23 +00:00
|
|
|
|
2017-03-01 09:10:10 +00:00
|
|
|
from multilib import multilib
|
2015-06-25 12:37:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Multilib(object):
|
2017-01-30 15:14:25 +00:00
|
|
|
"""This class decides whether a package should be multilib.
|
|
|
|
|
|
|
|
To use it, create an instance and call the ``is_multilib`` method on it.
|
|
|
|
The blacklist and whitelist in constructor should be sets of package names.
|
|
|
|
|
|
|
|
It may be more convenient to create the instance with the ``from_globs``
|
|
|
|
method that accepts a DNF sach and an iterable of globs that will be used
|
|
|
|
to find package names.
|
|
|
|
"""
|
|
|
|
def __init__(self, methods, blacklist, whitelist):
|
2017-01-30 13:27:17 +00:00
|
|
|
self.methods = {}
|
2017-01-30 15:14:25 +00:00
|
|
|
self.blacklist = blacklist
|
|
|
|
self.whitelist = whitelist
|
2015-06-25 12:37:23 +00:00
|
|
|
|
2017-03-01 09:10:10 +00:00
|
|
|
self.all_methods = {
|
|
|
|
'none': multilib.NoMultilibMethod(None),
|
|
|
|
'all': multilib.AllMultilibMethod(None),
|
|
|
|
'devel': multilib.DevelMultilibMethod(None),
|
|
|
|
'runtime': multilib.RuntimeMultilibMethod(None),
|
|
|
|
}
|
|
|
|
|
2017-01-30 13:27:17 +00:00
|
|
|
for method in methods:
|
2017-03-01 09:10:10 +00:00
|
|
|
self.methods[method] = self.all_methods[method]
|
2015-06-25 12:37:23 +00:00
|
|
|
|
2017-01-30 15:14:25 +00:00
|
|
|
@classmethod
|
|
|
|
def from_globs(cls, sack, methods, blacklist=None, whitelist=None):
|
|
|
|
"""Create a Multilib instance with expanded blacklist and whitelist."""
|
|
|
|
return cls(methods,
|
|
|
|
_expand_list(sack, blacklist or []),
|
|
|
|
_expand_list(sack, whitelist or []))
|
2015-06-25 12:37:23 +00:00
|
|
|
|
|
|
|
def is_multilib(self, pkg):
|
2017-01-30 15:14:25 +00:00
|
|
|
if pkg.name in self.blacklist:
|
2015-06-25 12:37:23 +00:00
|
|
|
return False
|
2017-01-30 15:14:25 +00:00
|
|
|
if pkg.name in self.whitelist:
|
2017-01-30 13:27:17 +00:00
|
|
|
return 'whitelist'
|
2017-09-05 08:01:21 +00:00
|
|
|
for method, cls in self.methods.items():
|
2017-03-01 09:10:10 +00:00
|
|
|
if cls.select(pkg):
|
2017-01-30 13:27:17 +00:00
|
|
|
return method
|
2015-06-25 12:37:23 +00:00
|
|
|
return False
|
2017-01-30 15:14:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _expand_list(sack, patterns):
|
|
|
|
"""Find all package names that match any of the provided patterns."""
|
|
|
|
return set(pkg.name for pkg in sack.query().filter(name__glob=list(patterns)))
|