|
Packit Service |
21c75c |
#
|
|
Packit Service |
21c75c |
# Copyright (C) 2016 Red Hat, Inc.
|
|
Packit Service |
21c75c |
#
|
|
Packit Service |
21c75c |
# This copyrighted material is made available to anyone wishing to use,
|
|
Packit Service |
21c75c |
# modify, copy, or redistribute it subject to the terms and conditions of
|
|
Packit Service |
21c75c |
# the GNU General Public License v.2, or (at your option) any later version.
|
|
Packit Service |
21c75c |
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
Packit Service |
21c75c |
# ANY WARRANTY expressed or implied, including the implied warranties of
|
|
Packit Service |
21c75c |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
Packit Service |
21c75c |
# Public License for more details. You should have received a copy of the
|
|
Packit Service |
21c75c |
# GNU General Public License along with this program; if not, write to the
|
|
Packit Service |
21c75c |
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit Service |
21c75c |
# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the
|
|
Packit Service |
21c75c |
# source code or documentation are not subject to the GNU General Public
|
|
Packit Service |
21c75c |
# License and may only be used or replicated with the express permission of
|
|
Packit Service |
21c75c |
# Red Hat, Inc.
|
|
Packit Service |
21c75c |
#
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
from __future__ import absolute_import
|
|
Packit Service |
21c75c |
from __future__ import unicode_literals
|
|
Packit Service |
21c75c |
from dnf.i18n import _
|
|
Packit Service |
21c75c |
from dnf.cli import commands
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
import argparse
|
|
Packit Service |
21c75c |
import dnf.exceptions
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
class CheckCommand(commands.Command):
|
|
Packit Service |
21c75c |
"""A class containing methods needed by the cli to execute the check
|
|
Packit Service |
21c75c |
command.
|
|
Packit Service |
21c75c |
"""
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
aliases = ('check',)
|
|
Packit Service |
21c75c |
summary = _('check for problems in the packagedb')
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
@staticmethod
|
|
Packit Service |
21c75c |
def set_argparser(parser):
|
|
Packit Service |
21c75c |
parser.add_argument('--all', dest='check_types',
|
|
Packit Service |
21c75c |
action='append_const', const='all',
|
|
Packit Service |
21c75c |
help=_('show all problems; default'))
|
|
Packit Service |
21c75c |
parser.add_argument('--dependencies', dest='check_types',
|
|
Packit Service |
21c75c |
action='append_const', const='dependencies',
|
|
Packit Service |
21c75c |
help=_('show dependency problems'))
|
|
Packit Service |
21c75c |
parser.add_argument('--duplicates', dest='check_types',
|
|
Packit Service |
21c75c |
action='append_const', const='duplicates',
|
|
Packit Service |
21c75c |
help=_('show duplicate problems'))
|
|
Packit Service |
21c75c |
parser.add_argument('--obsoleted', dest='check_types',
|
|
Packit Service |
21c75c |
action='append_const', const='obsoleted',
|
|
Packit Service |
21c75c |
help=_('show obsoleted packages'))
|
|
Packit Service |
21c75c |
parser.add_argument('--provides', dest='check_types',
|
|
Packit Service |
21c75c |
action='append_const', const='provides',
|
|
Packit Service |
21c75c |
help=_('show problems with provides'))
|
|
Packit Service |
21c75c |
# Add compatibility with yum but invisible in help
|
|
Packit Service |
21c75c |
# In choices [] allows to return empty list if no argument otherwise it fails
|
|
Packit Service |
21c75c |
parser.add_argument('check_yum_types', nargs='*', choices=[
|
|
Packit Service |
21c75c |
'all', 'dependencies', 'duplicates', 'obsoleted', 'provides', []],
|
|
Packit Service |
21c75c |
help=argparse.SUPPRESS)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def configure(self):
|
|
Packit Service |
21c75c |
self.cli.demands.sack_activation = True
|
|
Packit Service |
21c75c |
if self.opts.check_yum_types:
|
|
Packit Service |
21c75c |
if self.opts.check_types:
|
|
Packit Service |
21c75c |
self.opts.check_types = self.opts.check_types + \
|
|
Packit Service |
21c75c |
self.opts.check_yum_types
|
|
Packit Service |
21c75c |
else:
|
|
Packit Service |
21c75c |
self.opts.check_types = self.opts.check_yum_types
|
|
Packit Service |
21c75c |
if not self.opts.check_types:
|
|
Packit Service |
21c75c |
self.opts.check_types = {'all'}
|
|
Packit Service |
21c75c |
else:
|
|
Packit Service |
21c75c |
self.opts.check_types = set(self.opts.check_types)
|
|
Packit Service |
21c75c |
self.base.conf.disable_excludes += ["all"]
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def run(self):
|
|
Packit Service |
21c75c |
output_set = set()
|
|
Packit Service |
21c75c |
q = self.base.sack.query().installed()
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
if self.opts.check_types.intersection({'all', 'dependencies'}):
|
|
Packit Service |
21c75c |
sack = None
|
|
Packit Service |
21c75c |
for pkg in q:
|
|
Packit Service |
21c75c |
for require in set(pkg.regular_requires) | set(set(pkg.requires_pre) - set(pkg.prereq_ignoreinst)):
|
|
Packit Service |
21c75c |
if str(require).startswith('rpmlib'):
|
|
Packit Service |
21c75c |
continue
|
|
Packit Service |
21c75c |
if not len(q.filter(provides=[require])):
|
|
Packit Service |
21c75c |
if str(require).startswith('('):
|
|
Packit Service |
21c75c |
# rich deps can be only tested by solver
|
|
Packit Service |
21c75c |
if sack is None:
|
|
Packit Service |
21c75c |
sack = dnf.sack.rpmdb_sack(self.base)
|
|
Packit Service |
21c75c |
selector = dnf.selector.Selector(sack)
|
|
Packit Service |
21c75c |
selector.set(provides=str(require))
|
|
Packit Service |
21c75c |
goal = dnf.goal.Goal(sack)
|
|
Packit Service |
21c75c |
goal.protect_running_kernel = self.base.conf.protect_running_kernel
|
|
Packit Service |
21c75c |
goal.install(select=selector, optional=False)
|
|
Packit Service |
21c75c |
solved = goal.run()
|
|
Packit Service |
21c75c |
# there ase only @system repo in sack, therefore solved is only in case
|
|
Packit Service |
21c75c |
# when rich deps doesn't require any additional package
|
|
Packit Service |
21c75c |
if solved:
|
|
Packit Service |
21c75c |
continue
|
|
Packit Service |
21c75c |
msg = _("{} has missing requires of {}")
|
|
Packit Service |
21c75c |
output_set.add(msg.format(
|
|
Packit Service |
21c75c |
self.base.output.term.bold(pkg),
|
|
Packit Service |
21c75c |
self.base.output.term.bold(require)))
|
|
Packit Service |
21c75c |
for conflict in pkg.conflicts:
|
|
Packit Service |
21c75c |
conflicted = q.filter(provides=[conflict],
|
|
Packit Service |
21c75c |
name=str(conflict).split()[0])
|
|
Packit Service |
21c75c |
for conflict_pkg in conflicted:
|
|
Packit Service |
21c75c |
msg = '{} has installed conflict "{}": {}'
|
|
Packit Service |
21c75c |
output_set.add(msg.format(
|
|
Packit Service |
21c75c |
self.base.output.term.bold(pkg),
|
|
Packit Service |
21c75c |
self.base.output.term.bold(conflict),
|
|
Packit Service |
21c75c |
self.base.output.term.bold(conflict_pkg)))
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
if self.opts.check_types.intersection({'all', 'duplicates'}):
|
|
Packit Service |
21c75c |
installonly = self.base._get_installonly_query(q)
|
|
Packit Service |
21c75c |
dups = q.duplicated().difference(installonly)._name_dict()
|
|
Packit Service |
21c75c |
for name, pkgs in dups.items():
|
|
Packit Service |
21c75c |
pkgs.sort()
|
|
Packit Service |
21c75c |
for dup in pkgs[1:]:
|
|
Packit Service |
21c75c |
msg = _("{} is a duplicate with {}").format(
|
|
Packit Service |
21c75c |
self.base.output.term.bold(pkgs[0]),
|
|
Packit Service |
21c75c |
self.base.output.term.bold(dup))
|
|
Packit Service |
21c75c |
output_set.add(msg)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
if self.opts.check_types.intersection({'all', 'obsoleted'}):
|
|
Packit Service |
21c75c |
for pkg in q:
|
|
Packit Service |
21c75c |
for obsolete in pkg.obsoletes:
|
|
Packit Service |
21c75c |
obsoleted = q.filter(provides=[obsolete],
|
|
Packit Service |
21c75c |
name=str(obsolete).split()[0])
|
|
Packit Service |
21c75c |
if len(obsoleted):
|
|
Packit Service |
21c75c |
msg = _("{} is obsoleted by {}").format(
|
|
Packit Service |
21c75c |
self.base.output.term.bold(obsoleted[0]),
|
|
Packit Service |
21c75c |
self.base.output.term.bold(pkg))
|
|
Packit Service |
21c75c |
output_set.add(msg)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
if self.opts.check_types.intersection({'all', 'provides'}):
|
|
Packit Service |
21c75c |
for pkg in q:
|
|
Packit Service |
21c75c |
for provide in pkg.provides:
|
|
Packit Service |
21c75c |
if pkg not in q.filter(provides=[provide]):
|
|
Packit Service |
21c75c |
msg = _("{} provides {} but it cannot be found")
|
|
Packit Service |
21c75c |
output_set.add(msg.format(
|
|
Packit Service |
21c75c |
self.base.output.term.bold(pkg),
|
|
Packit Service |
21c75c |
self.base.output.term.bold(provide)))
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
for msg in sorted(output_set):
|
|
Packit Service |
21c75c |
print(msg)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
if output_set:
|
|
Packit Service |
21c75c |
raise dnf.exceptions.Error(
|
|
Packit Service |
21c75c |
'Check discovered {} problem(s)'.format(len(output_set)))
|