From 130509a8e4ab81db54117865a99aa8f90f3fa309 Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Tue, 18 Sep 2018 10:33:06 +0200 Subject: [PATCH] support yum and dnf python bindings --- bootstrap.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/bootstrap.py b/bootstrap.py index 3a37dc2..99b4e4b 100755 --- a/bootstrap.py +++ b/bootstrap.py @@ -23,7 +23,12 @@ from optparse import OptionParser from urllib import urlencode from ConfigParser import SafeConfigParser -import yum # pylint:disable=import-error +try: + import yum # pylint:disable=import-error + USE_YUM = True +except ImportError: + import dnf # pylint:disable=import-error + USE_YUM = False import rpm # pylint:disable=import-error import rpmUtils.miscutils # pylint:disable=import-error @@ -197,16 +202,25 @@ def install_prereqs(): if options.deps_repository_url: print_generic("Enabling %s as a repository for dependency RPMs" % options.deps_repository_url) setup_yum_repo(options.deps_repository_url, options.deps_repository_gpg_key) - yum_base = yum.YumBase() - pkg_list = yum_base.doPackageLists(patterns=['subscription-manager']) + if USE_YUM: + yum_base = yum.YumBase() + pkg_list = yum_base.doPackageLists(patterns=['subscription-manager']) + subman_installed = pkg_list.installed + subman_available = pkg_list.available + else: + dnf_base = dnf.Base() + dnf_base.fill_sack() + pkg_list = dnf_base.sack.query().filter(name='subscription-manager') + subman_installed = pkg_list.installed().run() + subman_available = pkg_list.available().run() call_yum("remove", "subscription-manager-gnome") - if pkg_list.installed: + if subman_installed: if check_rhn_registration() and 'migration' not in options.skip: print_generic("installing subscription-manager-migration") call_yum("install", "'subscription-manager-migration-*'", False) print_generic("subscription-manager is installed already. Attempting update") call_yum("update", "subscription-manager 'subscription-manager-migration-*'", False) - elif pkg_list.available: + elif subman_available: print_generic("subscription-manager NOT installed. Installing.") call_yum("install", "subscription-manager 'subscription-manager-migration-*'") else: