|
Packit Service |
21c75c |
# Copyright (C) 2015 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 |
"""A plugin that lists installed packages that are obsolted by any available package"""
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
from dnf.i18n import _
|
|
Packit Service |
21c75c |
import dnf
|
|
Packit Service |
21c75c |
import dnf.cli
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
# If you only plan to create a new dnf subcommand in a plugin
|
|
Packit Service |
21c75c |
# you can use @dnf.plugin.register_command decorator instead of creating
|
|
Packit Service |
21c75c |
# a Plugin class which only registers the command
|
|
Packit Service |
21c75c |
# (for full-fledged Plugin class see examples/install_plugin.py)
|
|
Packit Service |
21c75c |
@dnf.plugin.register_command
|
|
Packit Service |
21c75c |
class Command(dnf.cli.Command):
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
"""A command that lists packages installed on the system that are
|
|
Packit Service |
21c75c |
obsoleted by packages in any known repository."""
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
# An alias is needed to invoke the command from command line.
|
|
Packit Service |
21c75c |
aliases = ['foo'] # <-- SET YOUR ALIAS HERE.
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
@staticmethod
|
|
Packit Service |
21c75c |
def set_argparser(parser):
|
|
Packit Service |
21c75c |
parser.add_argument("package", nargs='*', metavar=_('PACKAGE'))
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def configure(self):
|
|
Packit Service |
21c75c |
"""Setup the demands."""
|
|
Packit Service |
21c75c |
# Repositories serve as sources of information about packages.
|
|
Packit Service |
21c75c |
self.cli.demands.available_repos = True
|
|
Packit Service |
21c75c |
# A sack is needed for querying.
|
|
Packit Service |
21c75c |
self.cli.demands.sack_activation = True
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def run(self):
|
|
Packit Service |
21c75c |
"""Run the command."""
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
obs_tuples = []
|
|
Packit Service |
21c75c |
# A query matches all available packages
|
|
Packit Service |
21c75c |
q = self.base.sack.query()
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
if not self.opts.package:
|
|
Packit Service |
21c75c |
# Narrow down query to match only installed packages
|
|
Packit Service |
21c75c |
inst = q.installed()
|
|
Packit Service |
21c75c |
# A dictionary containing list of obsoleted packages
|
|
Packit Service |
21c75c |
for new in q.filter(obsoletes=inst):
|
|
Packit Service |
21c75c |
obs_reldeps = new.obsoletes
|
|
Packit Service |
21c75c |
obsoleted = inst.filter(provides=obs_reldeps).run()
|
|
Packit Service |
21c75c |
obs_tuples.extend([(new, old) for old in obsoleted])
|
|
Packit Service |
21c75c |
else:
|
|
Packit Service |
21c75c |
for pkg_spec in self.opts.package:
|
|
Packit Service |
21c75c |
# A subject serves for parsing package format from user input
|
|
Packit Service |
21c75c |
subj = dnf.subject.Subject(pkg_spec)
|
|
Packit Service |
21c75c |
# A query restricted to installed packages matching given subject
|
|
Packit Service |
21c75c |
inst = subj.get_best_query(self.base.sack).installed()
|
|
Packit Service |
21c75c |
for new in q.filter(obsoletes=inst):
|
|
Packit Service |
21c75c |
obs_reldeps = new.obsoletes
|
|
Packit Service |
21c75c |
obsoleted = inst.filter(provides=obs_reldeps).run()
|
|
Packit Service |
21c75c |
obs_tuples.extend([(new, old) for old in obsoleted])
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
if not obs_tuples:
|
|
Packit Service |
21c75c |
raise dnf.exceptions.Error('No matching Packages to list')
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
for (new, old) in obs_tuples:
|
|
Packit Service |
21c75c |
print('%s.%s obsoletes %s.%s' %
|
|
Packit Service |
21c75c |
(new.name, new.arch, old.name, old.arch))
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
|