|
Packit |
6f3914 |
# updateinfo.py
|
|
Packit |
6f3914 |
# UpdateInfo CLI command.
|
|
Packit |
6f3914 |
#
|
|
Packit |
6f3914 |
# Copyright (C) 2014-2016 Red Hat, Inc.
|
|
Packit |
6f3914 |
#
|
|
Packit |
6f3914 |
# This copyrighted material is made available to anyone wishing to use,
|
|
Packit |
6f3914 |
# modify, copy, or redistribute it subject to the terms and conditions of
|
|
Packit |
6f3914 |
# the GNU General Public License v.2, or (at your option) any later version.
|
|
Packit |
6f3914 |
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
Packit |
6f3914 |
# ANY WARRANTY expressed or implied, including the implied warranties of
|
|
Packit |
6f3914 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
Packit |
6f3914 |
# Public License for more details. You should have received a copy of the
|
|
Packit |
6f3914 |
# GNU General Public License along with this program; if not, write to the
|
|
Packit |
6f3914 |
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit |
6f3914 |
# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the
|
|
Packit |
6f3914 |
# source code or documentation are not subject to the GNU General Public
|
|
Packit |
6f3914 |
# License and may only be used or replicated with the express permission of
|
|
Packit |
6f3914 |
# Red Hat, Inc.
|
|
Packit |
6f3914 |
#
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
"""UpdateInfo CLI command."""
|
|
Packit |
6f3914 |
from __future__ import absolute_import
|
|
Packit |
6f3914 |
from __future__ import print_function
|
|
Packit |
6f3914 |
from __future__ import unicode_literals
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
import collections
|
|
Packit |
6f3914 |
import fnmatch
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
import hawkey
|
|
Packit |
6f3914 |
from dnf.cli import commands
|
|
Packit |
6f3914 |
from dnf.cli.option_parser import OptionParser
|
|
Packit |
6f3914 |
from dnf.i18n import _, exact_width
|
|
Packit |
6f3914 |
from dnf.pycomp import unicode
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
def _maxlen(iterable):
|
|
Packit |
6f3914 |
"""Return maximum length of items in a non-empty iterable."""
|
|
Packit |
6f3914 |
return max(exact_width(item) for item in iterable)
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
class UpdateInfoCommand(commands.Command):
|
|
Packit |
6f3914 |
"""Implementation of the UpdateInfo command."""
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
TYPE2LABEL = {hawkey.ADVISORY_BUGFIX: _('bugfix'),
|
|
Packit |
6f3914 |
hawkey.ADVISORY_ENHANCEMENT: _('enhancement'),
|
|
Packit |
6f3914 |
hawkey.ADVISORY_SECURITY: _('security'),
|
|
Packit |
6f3914 |
hawkey.ADVISORY_UNKNOWN: _('unknown'),
|
|
Packit |
6f3914 |
hawkey.ADVISORY_NEWPACKAGE: _('newpackage')}
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
SECURITY2LABEL = {'Critical': _('Critical/Sec.'),
|
|
Packit |
6f3914 |
'Important': _('Important/Sec.'),
|
|
Packit |
6f3914 |
'Moderate': _('Moderate/Sec.'),
|
|
Packit |
6f3914 |
'Low': _('Low/Sec.')}
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
direct_commands = {'list-updateinfo' : 'list',
|
|
Packit |
6f3914 |
'list-security' : 'list',
|
|
Packit |
6f3914 |
'list-sec' : 'list',
|
|
Packit |
6f3914 |
'info-updateinfo' : 'info',
|
|
Packit |
6f3914 |
'info-security' : 'info',
|
|
Packit |
6f3914 |
'info-sec' : 'info',
|
|
Packit |
6f3914 |
'summary-updateinfo' : 'summary'}
|
|
Packit |
6f3914 |
aliases = ['updateinfo'] + list(direct_commands.keys())
|
|
Packit |
6f3914 |
summary = _('display advisories about packages')
|
|
Packit |
6f3914 |
availability_default = 'available'
|
|
Packit |
6f3914 |
availabilities = ['installed', 'updates', 'all', availability_default]
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
def __init__(self, cli):
|
|
Packit |
6f3914 |
"""Initialize the command."""
|
|
Packit |
6f3914 |
super(UpdateInfoCommand, self).__init__(cli)
|
|
Packit |
6f3914 |
self._installed_query = None
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
@staticmethod
|
|
Packit |
6f3914 |
def set_argparser(parser):
|
|
Packit |
6f3914 |
availability = parser.add_mutually_exclusive_group()
|
|
Packit |
6f3914 |
availability.add_argument(
|
|
Packit |
6f3914 |
"--available", dest='_availability', const='available', action='store_const',
|
|
Packit |
6f3914 |
help=_("advisories about newer versions of installed packages (default)"))
|
|
Packit |
6f3914 |
availability.add_argument(
|
|
Packit |
6f3914 |
"--installed", dest='_availability', const='installed', action='store_const',
|
|
Packit |
6f3914 |
help=_("advisories about equal and older versions of installed packages"))
|
|
Packit |
6f3914 |
availability.add_argument(
|
|
Packit |
6f3914 |
"--updates", dest='_availability', const='updates', action='store_const',
|
|
Packit |
6f3914 |
help=_("advisories about newer versions of those installed packages "
|
|
Packit |
6f3914 |
"for which a newer version is available"))
|
|
Packit |
6f3914 |
availability.add_argument(
|
|
Packit |
6f3914 |
"--all", dest='_availability', const='all', action='store_const',
|
|
Packit |
6f3914 |
help=_("advisories about any versions of installed packages"))
|
|
Packit |
6f3914 |
cmds = ['summary', 'list', 'info']
|
|
Packit |
6f3914 |
output_format = parser.add_mutually_exclusive_group()
|
|
Packit |
6f3914 |
output_format.add_argument("--summary", dest='_spec_action', const='summary',
|
|
Packit |
6f3914 |
action='store_const',
|
|
Packit |
6f3914 |
help=_('show summary of advisories (default)'))
|
|
Packit |
6f3914 |
output_format.add_argument("--list", dest='_spec_action', const='list',
|
|
Packit |
6f3914 |
action='store_const',
|
|
Packit |
6f3914 |
help=_('show list of advisories'))
|
|
Packit |
6f3914 |
output_format.add_argument("--info", dest='_spec_action', const='info',
|
|
Packit |
6f3914 |
action='store_const',
|
|
Packit |
6f3914 |
help=_('show info of advisories'))
|
|
Packit |
6f3914 |
parser.add_argument("--with-cve", dest='with_cve', default=False,
|
|
Packit |
6f3914 |
action='store_true',
|
|
Packit |
6f3914 |
help=_('show only advisories with CVE reference'))
|
|
Packit |
6f3914 |
parser.add_argument("--with-bz", dest='with_bz', default=False,
|
|
Packit |
6f3914 |
action='store_true',
|
|
Packit |
6f3914 |
help=_('show only advisories with bugzilla reference'))
|
|
Packit |
6f3914 |
parser.add_argument('spec', nargs='*', metavar='SPEC',
|
|
Packit |
6f3914 |
choices=cmds, default=cmds[0],
|
|
Packit |
6f3914 |
action=OptionParser.PkgNarrowCallback,
|
|
Packit |
6f3914 |
help=_("Package specification"))
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
def configure(self):
|
|
Packit |
6f3914 |
"""Do any command-specific configuration based on command arguments."""
|
|
Packit |
6f3914 |
self.cli.demands.available_repos = True
|
|
Packit |
6f3914 |
self.cli.demands.sack_activation = True
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
if self.opts.command[0] in self.direct_commands:
|
|
Packit |
6f3914 |
# we were called with direct command
|
|
Packit |
6f3914 |
self.opts.spec_action = self.direct_commands[self.opts.command[0]]
|
|
Packit |
6f3914 |
else:
|
|
Packit |
6f3914 |
if self.opts._spec_action:
|
|
Packit |
6f3914 |
self.opts.spec_action = self.opts._spec_action
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
if self.opts._availability:
|
|
Packit |
6f3914 |
self.opts.availability = self.opts._availability
|
|
Packit |
6f3914 |
else:
|
|
Packit |
6f3914 |
# yum compatibility - search for all|available|installed|updates in spec[0]
|
|
Packit |
6f3914 |
if not self.opts.spec or self.opts.spec[0] not in self.availabilities:
|
|
Packit |
6f3914 |
self.opts.availability = self.availability_default
|
|
Packit |
6f3914 |
else:
|
|
Packit |
6f3914 |
self.opts.availability = self.opts.spec.pop(0)
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
# filtering by advisory types (security/bugfix/enhancement/newpackage)
|
|
Packit |
6f3914 |
self.opts._advisory_types = set()
|
|
Packit |
6f3914 |
if self.opts.bugfix:
|
|
Packit |
6f3914 |
self.opts._advisory_types.add(hawkey.ADVISORY_BUGFIX)
|
|
Packit |
6f3914 |
if self.opts.enhancement:
|
|
Packit |
6f3914 |
self.opts._advisory_types.add(hawkey.ADVISORY_ENHANCEMENT)
|
|
Packit |
6f3914 |
if self.opts.newpackage:
|
|
Packit |
6f3914 |
self.opts._advisory_types.add(hawkey.ADVISORY_NEWPACKAGE)
|
|
Packit |
6f3914 |
if self.opts.security:
|
|
Packit |
6f3914 |
self.opts._advisory_types.add(hawkey.ADVISORY_SECURITY)
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
# yum compatibility - yum accepts types also as positional arguments
|
|
Packit |
6f3914 |
if self.opts.spec:
|
|
Packit |
6f3914 |
spec = self.opts.spec.pop(0)
|
|
Packit |
6f3914 |
if spec == 'bugfix':
|
|
Packit |
6f3914 |
self.opts._advisory_types.add(hawkey.ADVISORY_BUGFIX)
|
|
Packit |
6f3914 |
elif spec == 'enhancement':
|
|
Packit |
6f3914 |
self.opts._advisory_types.add(hawkey.ADVISORY_ENHANCEMENT)
|
|
Packit |
6f3914 |
elif spec in ('security', 'sec'):
|
|
Packit |
6f3914 |
self.opts._advisory_types.add(hawkey.ADVISORY_SECURITY)
|
|
Packit |
6f3914 |
elif spec == 'newpackage':
|
|
Packit |
6f3914 |
self.opts._advisory_types.add(hawkey.ADVISORY_NEWPACKAGE)
|
|
Packit |
6f3914 |
elif spec in ('bugzillas', 'bzs'):
|
|
Packit |
6f3914 |
self.opts.with_bz = True
|
|
Packit |
6f3914 |
elif spec == 'cves':
|
|
Packit |
6f3914 |
self.opts.with_cve = True
|
|
Packit |
6f3914 |
else:
|
|
Packit |
6f3914 |
self.opts.spec.insert(0, spec)
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
if self.opts.advisory:
|
|
Packit |
6f3914 |
self.opts.spec.extend(self.opts.advisory)
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
def run(self):
|
|
Packit |
6f3914 |
"""Execute the command with arguments."""
|
|
Packit |
6f3914 |
if self.opts.availability == 'installed':
|
|
Packit |
6f3914 |
apkg_adv_insts = self.installed_apkg_adv_insts(self.opts.spec)
|
|
Packit |
6f3914 |
description = _('installed')
|
|
Packit |
6f3914 |
elif self.opts.availability == 'updates':
|
|
Packit |
6f3914 |
apkg_adv_insts = self.updating_apkg_adv_insts(self.opts.spec)
|
|
Packit |
6f3914 |
description = _('updates')
|
|
Packit |
6f3914 |
elif self.opts.availability == 'all':
|
|
Packit |
6f3914 |
apkg_adv_insts = self.all_apkg_adv_insts(self.opts.spec)
|
|
Packit |
6f3914 |
description = _('all')
|
|
Packit |
6f3914 |
else:
|
|
Packit |
6f3914 |
apkg_adv_insts = self.available_apkg_adv_insts(self.opts.spec)
|
|
Packit |
6f3914 |
description = _('available')
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
if self.opts.spec_action == 'list':
|
|
Packit |
6f3914 |
self.display_list(apkg_adv_insts)
|
|
Packit |
6f3914 |
elif self.opts.spec_action == 'info':
|
|
Packit |
6f3914 |
self.display_info(apkg_adv_insts)
|
|
Packit |
6f3914 |
else:
|
|
Packit |
6f3914 |
self.display_summary(apkg_adv_insts, description)
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
def _newer_equal_installed(self, apackage):
|
|
Packit |
6f3914 |
if self._installed_query is None:
|
|
Packit |
6f3914 |
self._installed_query = self.base.sack.query().installed().apply()
|
|
Packit |
6f3914 |
q = self._installed_query.filter(name=apackage.name, evr__gte=apackage.evr)
|
|
Packit |
6f3914 |
return len(q) > 0
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
def _advisory_matcher(self, advisory):
|
|
Packit |
6f3914 |
if not self.opts._advisory_types \
|
|
Packit |
6f3914 |
and not self.opts.spec \
|
|
Packit |
6f3914 |
and not self.opts.severity \
|
|
Packit |
6f3914 |
and not self.opts.bugzilla \
|
|
Packit |
6f3914 |
and not self.opts.cves \
|
|
Packit |
6f3914 |
and not self.opts.with_cve \
|
|
Packit |
6f3914 |
and not self.opts.with_bz:
|
|
Packit |
6f3914 |
return True
|
|
Packit |
6f3914 |
if advisory.type in self.opts._advisory_types:
|
|
Packit |
6f3914 |
return True
|
|
Packit |
6f3914 |
if any(fnmatch.fnmatchcase(advisory.id, pat) for pat in self.opts.spec):
|
|
Packit |
6f3914 |
return True
|
|
Packit |
6f3914 |
if self.opts.severity and advisory.severity in self.opts.severity:
|
|
Packit |
6f3914 |
return True
|
|
Packit |
6f3914 |
if self.opts.bugzilla and any([advisory.match_bug(bug) for bug in self.opts.bugzilla]):
|
|
Packit |
6f3914 |
return True
|
|
Packit |
6f3914 |
if self.opts.cves and any([advisory.match_cve(cve) for cve in self.opts.cves]):
|
|
Packit |
6f3914 |
return True
|
|
Packit |
6f3914 |
if self.opts.with_cve:
|
|
Packit |
6f3914 |
if any([ref.type == hawkey.REFERENCE_CVE for ref in advisory.references]):
|
|
Packit |
6f3914 |
return True
|
|
Packit |
6f3914 |
if self.opts.with_bz:
|
|
Packit |
6f3914 |
if any([ref.type == hawkey.REFERENCE_BUGZILLA for ref in advisory.references]):
|
|
Packit |
6f3914 |
return True
|
|
Packit |
6f3914 |
return False
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
def _apackage_advisory_installed(self, pkgs_query, cmptype, specs):
|
|
Packit |
6f3914 |
"""Return (adv. package, advisory, installed) triplets."""
|
|
Packit |
6f3914 |
for apackage in pkgs_query.get_advisory_pkgs(cmptype):
|
|
Packit |
6f3914 |
advisory = apackage.get_advisory(self.base.sack)
|
|
Packit |
6f3914 |
advisory_match = self._advisory_matcher(advisory)
|
|
Packit |
6f3914 |
apackage_match = any(fnmatch.fnmatchcase(apackage.name, pat)
|
|
Packit |
6f3914 |
for pat in self.opts.spec)
|
|
Packit |
6f3914 |
if advisory_match or apackage_match:
|
|
Packit |
6f3914 |
installed = self._newer_equal_installed(apackage)
|
|
Packit |
6f3914 |
yield apackage, advisory, installed
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
def running_kernel_pkgs(self):
|
|
Packit |
6f3914 |
"""Return query containing packages of currently running kernel"""
|
|
Packit |
6f3914 |
sack = self.base.sack
|
|
Packit |
6f3914 |
q = sack.query().filterm(empty=True)
|
|
Packit |
6f3914 |
kernel = sack.get_running_kernel()
|
|
Packit |
6f3914 |
if kernel:
|
|
Packit |
6f3914 |
q = q.union(sack.query().filterm(sourcerpm=kernel.sourcerpm))
|
|
Packit |
6f3914 |
return q
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
def available_apkg_adv_insts(self, specs):
|
|
Packit |
6f3914 |
"""Return available (adv. package, adv., inst.) triplets"""
|
|
Packit |
6f3914 |
# check advisories for the latest installed packages
|
|
Packit |
6f3914 |
q = self.base.sack.query().installed().latest(1)
|
|
Packit |
6f3914 |
# plus packages of the running kernel
|
|
Packit |
6f3914 |
q = q.union(self.running_kernel_pkgs().installed())
|
|
Packit |
6f3914 |
return self._apackage_advisory_installed(q, hawkey.GT, specs)
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
def installed_apkg_adv_insts(self, specs):
|
|
Packit |
6f3914 |
"""Return installed (adv. package, adv., inst.) triplets"""
|
|
Packit |
6f3914 |
return self._apackage_advisory_installed(
|
|
Packit |
6f3914 |
self.base.sack.query().installed(), hawkey.LT | hawkey.EQ, specs)
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
def updating_apkg_adv_insts(self, specs):
|
|
Packit |
6f3914 |
"""Return updating (adv. package, adv., inst.) triplets"""
|
|
Packit |
6f3914 |
return self._apackage_advisory_installed(
|
|
Packit |
6f3914 |
self.base.sack.query().filterm(upgradable=True), hawkey.GT, specs)
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
def all_apkg_adv_insts(self, specs):
|
|
Packit |
6f3914 |
"""Return installed (adv. package, adv., inst.) triplets"""
|
|
Packit |
6f3914 |
return self._apackage_advisory_installed(
|
|
Packit |
6f3914 |
self.base.sack.query().installed(), hawkey.LT | hawkey.EQ | hawkey.GT, specs)
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
def _summary(self, apkg_adv_insts):
|
|
Packit |
6f3914 |
"""Make the summary of advisories."""
|
|
Packit |
6f3914 |
# Remove duplicate advisory IDs. We assume that the ID is unique within
|
|
Packit |
6f3914 |
# a repository and two advisories with the same IDs in different
|
|
Packit |
6f3914 |
# repositories must have the same type.
|
|
Packit |
6f3914 |
id2type = {}
|
|
Packit |
6f3914 |
for (apkg, advisory, installed) in apkg_adv_insts:
|
|
Packit |
6f3914 |
id2type[advisory.id] = advisory.type
|
|
Packit |
6f3914 |
if advisory.type == hawkey.ADVISORY_SECURITY:
|
|
Packit |
6f3914 |
id2type[(advisory.id, advisory.severity)] = (advisory.type, advisory.severity)
|
|
Packit |
6f3914 |
return collections.Counter(id2type.values())
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
def display_summary(self, apkg_adv_insts, description):
|
|
Packit |
6f3914 |
"""Display the summary of advisories."""
|
|
Packit |
6f3914 |
typ2cnt = self._summary(apkg_adv_insts)
|
|
Packit |
6f3914 |
if typ2cnt:
|
|
Packit |
6f3914 |
print(_('Updates Information Summary: ') + description)
|
|
Packit |
6f3914 |
# Convert types to strings and order the entries.
|
|
Packit |
6f3914 |
label_counts = [
|
|
Packit |
6f3914 |
(0, _('New Package notice(s)'), typ2cnt[hawkey.ADVISORY_NEWPACKAGE]),
|
|
Packit |
6f3914 |
(0, _('Security notice(s)'), typ2cnt[hawkey.ADVISORY_SECURITY]),
|
|
Packit |
6f3914 |
(1, _('Critical Security notice(s)'),
|
|
Packit |
6f3914 |
typ2cnt[(hawkey.ADVISORY_SECURITY, 'Critical')]),
|
|
Packit |
6f3914 |
(1, _('Important Security notice(s)'),
|
|
Packit |
6f3914 |
typ2cnt[(hawkey.ADVISORY_SECURITY, 'Important')]),
|
|
Packit |
6f3914 |
(1, _('Moderate Security notice(s)'),
|
|
Packit |
6f3914 |
typ2cnt[(hawkey.ADVISORY_SECURITY, 'Moderate')]),
|
|
Packit |
6f3914 |
(1, _('Low Security notice(s)'),
|
|
Packit |
6f3914 |
typ2cnt[(hawkey.ADVISORY_SECURITY, 'Low')]),
|
|
Packit |
6f3914 |
(1, _('Unknown Security notice(s)'),
|
|
Packit |
6f3914 |
typ2cnt[(hawkey.ADVISORY_SECURITY, None)]),
|
|
Packit |
6f3914 |
(0, _('Bugfix notice(s)'), typ2cnt[hawkey.ADVISORY_BUGFIX]),
|
|
Packit |
6f3914 |
(0, _('Enhancement notice(s)'), typ2cnt[hawkey.ADVISORY_ENHANCEMENT]),
|
|
Packit |
6f3914 |
(0, _('other notice(s)'), typ2cnt[hawkey.ADVISORY_UNKNOWN])]
|
|
Packit |
6f3914 |
width = _maxlen(unicode(v[2]) for v in label_counts if v[2])
|
|
Packit |
6f3914 |
for indent, label, count in label_counts:
|
|
Packit |
6f3914 |
if not count:
|
|
Packit |
6f3914 |
continue
|
|
Packit |
6f3914 |
print(' %*s %s' % (width + 4 * indent, unicode(count), label))
|
|
Packit |
6f3914 |
if self.base.conf.autocheck_running_kernel:
|
|
Packit |
6f3914 |
self.cli._check_running_kernel()
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
def display_list(self, apkg_adv_insts):
|
|
Packit |
6f3914 |
"""Display the list of advisories."""
|
|
Packit |
6f3914 |
def inst2mark(inst):
|
|
Packit |
6f3914 |
if not self.opts.availability == 'all':
|
|
Packit |
6f3914 |
return ''
|
|
Packit |
6f3914 |
elif inst:
|
|
Packit |
6f3914 |
return 'i '
|
|
Packit |
6f3914 |
else:
|
|
Packit |
6f3914 |
return ' '
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
def type2label(typ, sev):
|
|
Packit |
6f3914 |
if typ == hawkey.ADVISORY_SECURITY:
|
|
Packit |
6f3914 |
return self.SECURITY2LABEL.get(sev, _('Unknown/Sec.'))
|
|
Packit |
6f3914 |
else:
|
|
Packit |
6f3914 |
return self.TYPE2LABEL.get(typ, _('unknown'))
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
nevra_inst_dict = dict()
|
|
Packit |
6f3914 |
for apkg, advisory, installed in apkg_adv_insts:
|
|
Packit |
6f3914 |
nevra = '%s-%s.%s' % (apkg.name, apkg.evr, apkg.arch)
|
|
Packit |
6f3914 |
if self.opts.with_cve or self.opts.with_bz:
|
|
Packit |
6f3914 |
for ref in advisory.references:
|
|
Packit |
6f3914 |
if ref.type == hawkey.REFERENCE_BUGZILLA and not self.opts.with_bz:
|
|
Packit |
6f3914 |
continue
|
|
Packit |
6f3914 |
elif ref.type == hawkey.REFERENCE_CVE and not self.opts.with_cve:
|
|
Packit |
6f3914 |
continue
|
|
Packit |
6f3914 |
nevra_inst_dict.setdefault((nevra, installed), dict())[ref.id] = (
|
|
Packit |
6f3914 |
advisory.type, advisory.severity)
|
|
Packit |
6f3914 |
else:
|
|
Packit |
6f3914 |
nevra_inst_dict.setdefault((nevra, installed), dict())[advisory.id] = (
|
|
Packit |
6f3914 |
advisory.type, advisory.severity)
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
advlist = []
|
|
Packit |
6f3914 |
# convert types to labels, find max len of advisory IDs and types
|
|
Packit |
6f3914 |
idw = tlw = 0
|
|
Packit |
6f3914 |
for (nevra, inst), id2type in sorted(nevra_inst_dict.items(), key=lambda x: x[0]):
|
|
Packit |
6f3914 |
for aid, atypesev in id2type.items():
|
|
Packit |
6f3914 |
idw = max(idw, len(aid))
|
|
Packit |
6f3914 |
label = type2label(*atypesev)
|
|
Packit |
6f3914 |
tlw = max(tlw, len(label))
|
|
Packit |
6f3914 |
advlist.append((inst2mark(inst), aid, label, nevra))
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
for (inst, aid, label, nevra) in advlist:
|
|
Packit |
6f3914 |
print('%s%-*s %-*s %s' % (inst, idw, aid, tlw, label, nevra))
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
def display_info(self, apkg_adv_insts):
|
|
Packit |
6f3914 |
"""Display the details about available advisories."""
|
|
Packit |
6f3914 |
arches = self.base.sack.list_arches()
|
|
Packit |
6f3914 |
verbose = self.base.conf.verbose
|
|
Packit |
6f3914 |
labels = (_('Update ID'), _('Type'), _('Updated'), _('Bugs'),
|
|
Packit |
6f3914 |
_('CVEs'), _('Description'), _('Severity'), _('Rights'),
|
|
Packit |
6f3914 |
_('Files'), _('Installed'))
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
def advisory2info(advisory, installed):
|
|
Packit |
6f3914 |
attributes = [
|
|
Packit |
6f3914 |
[advisory.id],
|
|
Packit |
6f3914 |
[self.TYPE2LABEL.get(advisory.type, _('unknown'))],
|
|
Packit |
6f3914 |
[unicode(advisory.updated)],
|
|
Packit |
6f3914 |
[],
|
|
Packit |
6f3914 |
[],
|
|
Packit |
6f3914 |
(advisory.description or '').splitlines(),
|
|
Packit |
6f3914 |
[advisory.severity],
|
|
Packit |
6f3914 |
(advisory.rights or '').splitlines(),
|
|
Packit |
6f3914 |
sorted(set(pkg.filename for pkg in advisory.packages
|
|
Packit |
6f3914 |
if pkg.arch in arches)),
|
|
Packit |
6f3914 |
None]
|
|
Packit |
6f3914 |
for ref in advisory.references:
|
|
Packit |
6f3914 |
if ref.type == hawkey.REFERENCE_BUGZILLA:
|
|
Packit |
6f3914 |
attributes[3].append('{} - {}'.format(ref.id, ref.title or ''))
|
|
Packit |
6f3914 |
elif ref.type == hawkey.REFERENCE_CVE:
|
|
Packit |
6f3914 |
attributes[4].append(ref.id)
|
|
Packit |
6f3914 |
attributes[3].sort()
|
|
Packit |
6f3914 |
attributes[4].sort()
|
|
Packit |
6f3914 |
if not verbose:
|
|
Packit |
6f3914 |
attributes[7] = None
|
|
Packit |
6f3914 |
attributes[8] = None
|
|
Packit |
6f3914 |
if self.opts.availability == 'all':
|
|
Packit |
6f3914 |
attributes[9] = [_('true') if installed else _('false')]
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
width = _maxlen(labels)
|
|
Packit |
6f3914 |
lines = []
|
|
Packit |
6f3914 |
lines.append('=' * 79)
|
|
Packit |
6f3914 |
lines.append(' ' + advisory.title)
|
|
Packit |
6f3914 |
lines.append('=' * 79)
|
|
Packit |
6f3914 |
for label, atr_lines in zip(labels, attributes):
|
|
Packit |
6f3914 |
if atr_lines in (None, [None]):
|
|
Packit |
6f3914 |
continue
|
|
Packit |
6f3914 |
for i, line in enumerate(atr_lines):
|
|
Packit |
6f3914 |
key = label if i == 0 else ''
|
|
Packit |
6f3914 |
key_padding = width - exact_width(key)
|
|
Packit |
6f3914 |
lines.append('%*s%s: %s' % (key_padding, "", key, line))
|
|
Packit |
6f3914 |
return '\n'.join(lines)
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
advisories = set()
|
|
Packit |
6f3914 |
for apkg, advisory, installed in apkg_adv_insts:
|
|
Packit |
6f3914 |
advisories.add(advisory2info(advisory, installed))
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
print("\n\n".join(sorted(advisories, key=lambda x: x.lower())))
|