Skip to content

Commit

Permalink
Use python-hawkey instead of rpm-python.
Browse files Browse the repository at this point in the history
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.

Signed-off-by: mulhern <amulhern@redhat.com>
  • Loading branch information
mulkieran committed May 18, 2015
1 parent 2038f95 commit a343df4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
19 changes: 9 additions & 10 deletions blivet/tasks/availability.py
Expand Up @@ -21,8 +21,7 @@

import abc
from distutils.version import LooseVersion
import rpm
import six
import hawkey

from six import add_metaclass

Expand Down Expand Up @@ -136,19 +135,19 @@ 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()
sack.load_system_repo()
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:
Expand Down
4 changes: 2 additions & 2 deletions python-blivet.spec
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit a343df4

Please sign in to comment.