[master 2/2] Use python-hawkey instead of rpm-python.

mulkieran installerbot-noreply at redhat.com
Thu May 21 17:17:19 UTC 2015


From: mulhern <amulhern at redhat.com>

The advantages are that the hawkey API is consistent between python
versions, and that it is a bit cleaner for this purpose.

python-hawkey adds two new dependencies above what rpm-python adds, but it
is required by dnf anyway, so it will likely be installed by most users.

Now raise an AvailabilityError if the number of packages is not exactly
equal to 1. This is more correct and is not going to cause more stack
traces, because the error is caught in the method that calls
packageVersion.

Now catch a possible IOError and reraise as AvailabilityError when loading
repo.

Signed-off-by: mulhern <amulhern at redhat.com>
---
 blivet/tasks/availability.py | 30 +++++++++++++++++++-----------
 python-blivet.spec           |  4 ++--
 2 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/blivet/tasks/availability.py b/blivet/tasks/availability.py
index b310cbe..efb8b75 100644
--- a/blivet/tasks/availability.py
+++ b/blivet/tasks/availability.py
@@ -21,8 +21,7 @@
 
 import abc
 from distutils.version import LooseVersion
-import rpm
-import six
+import hawkey
 
 from six import add_metaclass
 
@@ -136,19 +135,28 @@ def __init__(self, package=None):
 
     @property
     def packageVersion(self):
-        """ Returns the version of the package.
+        """ Returns the version of the installed package.
 
             :returns: the package version
             :rtype: LooseVersion
+            :raises AvailabilityError: on failure to obtain package version
         """
-        ts = rpm.TransactionSet()
-        info = ts.dbMatch("provides", self.package.package_name)
-        if len(info) == 0:
-            raise AvailabilityError("Could not determine package version for %s" % self.package.package_name)
-        version = next(info)['version']
-        if six.PY3:
-            version = version.decode()
-        return LooseVersion(version)
+        sack = hawkey.Sack()
+
+        try:
+            sack.load_system_repo()
+        except IOError as e:
+            # hawkey has been observed allowing an IOError to propagate to
+            # caller with message "Failed calculating RPMDB checksum."
+            # See: https://bugzilla.redhat.com/show_bug.cgi?id=1223914
+            raise AvailabilityError("Could not determine package version for %s: %s" % (self.package.package_name, e))
+
+        query = hawkey.Query(sack).filter(name=self.package.package_name, latest=True)
+        packages = query.run()
+        if len(packages) != 1:
+            raise AvailabilityError("Could not determine package version for %s: unable to obtain package information from repo" % self.package.package_name)
+
+        return LooseVersion(packages[0].version)
 
     def availabilityErrors(self, resource):
         if self._availabilityErrors is not None and CACHE_AVAILABILITY:
diff --git a/python-blivet.spec b/python-blivet.spec
index 9715db8..0e3fcbd 100644
--- a/python-blivet.spec
+++ b/python-blivet.spec
@@ -43,7 +43,7 @@ Requires: libselinux-python
 Requires: libblockdev >= %{libblockdevver}
 Requires: libblockdev-plugins-all >= %{libblockdevver}
 Requires: libselinux-python
-Requires: rpm-python
+Requires: python-hawkey
 
 %description
 The python-blivet package is a python module for examining and modifying
@@ -65,7 +65,7 @@ Requires: util-linux >= %{utillinuxver}
 Requires: dosfstools
 Requires: e2fsprogs >= %{e2fsver}
 Requires: lsof
-Requires: rpm-python3
+Requires: python3-hawkey
 
 %description -n python3-%{realname}
 The python3-%{realname} is a python3 package for examining and modifying storage


-- 
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/ce805b043c5304b1fe6a51a9be3c43965b2850aa


More information about the anaconda-patches mailing list