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

mulkieran installerbot-noreply at redhat.com
Wed May 20 19:18:39 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 | 22 ++++++++++++----------
 python-blivet.spec           |  4 ++--
 2 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/blivet/tasks/availability.py b/blivet/tasks/availability.py
index b310cbe..268ce18 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,22 @@ 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:
+        sack = hawkey.Sack()
+        try:
+            sack.load_system_repo()
+        except IOError as e:
+            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" % self.package.package_name)
-        version = next(info)['version']
-        if six.PY3:
-            version = version.decode()
-        return LooseVersion(version)
+        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/e266f7fd6b451f1f0290219724a65a913c172922


More information about the anaconda-patches mailing list