Blame libexec/dnf-utils.in

Packit 3a9065
#!@PYTHON_EXECUTABLE@
Packit 3a9065
# The dnf-utils executable script.
Packit 3a9065
#
Packit 3a9065
# Copyright (C) 2017 Red Hat, Inc.
Packit 3a9065
#
Packit 3a9065
# This copyrighted material is made available to anyone wishing to use,
Packit 3a9065
# modify, copy, or redistribute it subject to the terms and conditions of
Packit 3a9065
# the GNU General Public License v.2, or (at your option) any later version.
Packit 3a9065
# This program is distributed in the hope that it will be useful, but WITHOUT
Packit 3a9065
# ANY WARRANTY expressed or implied, including the implied warranties of
Packit 3a9065
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
Packit 3a9065
# Public License for more details.  You should have received a copy of the
Packit 3a9065
# GNU General Public License along with this program; if not, write to the
Packit 3a9065
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
Packit 3a9065
# 02110-1301, USA.  Any Red Hat trademarks that are incorporated in the
Packit 3a9065
# source code or documentation are not subject to the GNU General Public
Packit 3a9065
# License and may only be used or replicated with the express permission of
Packit 3a9065
# Red Hat, Inc.
Packit 3a9065
#
Packit 3a9065
Packit 3a9065
from __future__ import unicode_literals
Packit 3a9065
import sys
Packit 3a9065
import os.path
Packit 3a9065
Packit 3a9065
MAPPING = {'debuginfo-install': ['debuginfo-install'],
Packit 3a9065
           'needs-restarting': ['needs-restarting'],
Packit 3a9065
           'find-repos-of-install': ['list', 'installed'],
Packit 3a9065
           'package-cleanup': [],
Packit 3a9065
           'repo-graph': ['repograph'],
Packit 3a9065
           'repoclosure': ['repoclosure'],
Packit 3a9065
           'repodiff': ['repodiff'],
Packit 3a9065
           'repomanage': ['repomanage'],
Packit 3a9065
           'repoquery': ['repoquery'],
Packit 3a9065
           'reposync': ['reposync'],
Packit 3a9065
           'repotrack': ['download', '--resolve', '--alldeps'],
Packit 3a9065
           'yum-builddep': ['builddep'],
Packit 3a9065
           'yum-config-manager': ['config-manager'],
Packit 3a9065
           'yum-debug-dump': ['debug-dump'],
Packit 3a9065
           'yum-debug-restore': ['debug-restore'],
Packit Service 2886e3
           'yum-groups-manager': ['groups-manager'],
Packit 3a9065
           'yumdownloader': ['download']
Packit 3a9065
           }
Packit 3a9065
Packit 3a9065
def suppress_keyboard_interrupt_message():
Packit 3a9065
    """Prevent unsightly KeyboardInterrupt tracebacks.
Packit 3a9065
Packit 3a9065
    Nothing will be printed to the terminal after an uncaught
Packit 3a9065
    :class:`exceptions.KeyboardInterrupt`.
Packit 3a9065
Packit 3a9065
    """
Packit 3a9065
    old_excepthook = sys.excepthook
Packit 3a9065
Packit 3a9065
    def new_hook(type, value, traceback):
Packit 3a9065
        if type != KeyboardInterrupt:
Packit 3a9065
            old_excepthook(type, value, traceback)
Packit 3a9065
        else:
Packit 3a9065
            pass
Packit 3a9065
Packit 3a9065
    sys.excepthook = new_hook
Packit 3a9065
Packit 3a9065
Packit 3a9065
# do this ASAP to prevent tracebacks after ^C during imports
Packit 3a9065
suppress_keyboard_interrupt_message()
Packit 3a9065
Packit 3a9065
if __name__ != "__main__":
Packit 3a9065
    sys.stderr.write('The executable DNF module must not be imported.')
Packit 3a9065
    sys.exit(1)
Packit 3a9065
Packit 3a9065
here = sys.path[0]
Packit 3a9065
if here != '/usr/bin':
Packit 3a9065
    # git checkout
Packit 3a9065
    import os
Packit 3a9065
    dnf_toplevel = os.path.dirname(here)
Packit 3a9065
    sys.path[0] = dnf_toplevel
Packit 3a9065
Packit 3a9065
from dnf.cli import main
Packit 3a9065
command = os.path.basename(sys.argv[0])
Packit 3a9065
args = sys.argv[1:]
Packit 3a9065
Packit 3a9065
if command == 'package-cleanup':
Packit 3a9065
    if '--dupes' in args:
Packit 3a9065
        args[args.index('--dupes')] = '--duplicates'
Packit 3a9065
        MAPPING[command] = ['repoquery']
Packit 3a9065
    elif '--leaves' in args:
Packit 3a9065
        args[args.index('--leaves')] = '--unneeded'
Packit 3a9065
        MAPPING[command] = ['repoquery']
Packit 3a9065
    elif '--orphans' in args:
Packit 3a9065
        args[args.index('--orphans')] = '--extras'
Packit 3a9065
        MAPPING[command] = ['repoquery']
Packit 3a9065
    elif '--problems' in args:
Packit 3a9065
        args[args.index('--problems')] = '--unsatisfied'
Packit 3a9065
        MAPPING[command] = ['repoquery']
Packit 3a9065
    elif '--cleandupes' in args:
Packit 3a9065
        args[args.index('--cleandupes')] = '--duplicates'
Packit 3a9065
        MAPPING[command] = ['remove']
Packit 3a9065
    else:
Packit 3a9065
        sys.stderr.write('package-cleanup has to be executed with one of the options: --dupes, '
Packit 3a9065
                         '--leaves, --orphans, --problems or --cleandupes\n')
Packit 3a9065
        sys.exit(1)
Packit 3a9065
Packit 3a9065
main.user_main(MAPPING[command] + args, exit_code=True)