[Yum-devel] [PATCH 2/2] Use rpmsack for retrieving system release version

Panu Matilainen pmatilai at laiskiainen.org
Tue Feb 15 11:06:38 UTC 2011


Avoids another lowlevel rpm routine usage where rpmsack provides
a nicer interface for the thing, and another step towards consolidating
rpm quirk handling to one spot.
---
 yum/config.py |   15 ++++++---------
 1 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/yum/config.py b/yum/config.py
index 9c2db93..af4565a 100644
--- a/yum/config.py
+++ b/yum/config.py
@@ -41,6 +41,7 @@ import rpmUtils.transaction
 import Errors
 import types
 from misc import get_uuid, read_in_items_from_dot_dir
+from rpmsack import RPMDBPackageSack
 
 # Alter/patch these to change the default checking...
 __pkgs_gpgcheck_default__ = False
@@ -1000,10 +1001,10 @@ def _getsysver(installroot, distroverpkg):
     @param distroverpkg: The value of the distroverpkg option.
     @return: The release version as a string (eg. '4' for FC4)
     '''
-    ts = rpmUtils.transaction.initReadOnlyTransaction(root=installroot)
-    ts.pushVSFlags(~(rpm._RPMVSF_NOSIGNATURES|rpm._RPMVSF_NODIGESTS))
+    rpmdb = RPMDBPackageSack(root=installroot)
+    # XXX rpmdb open error should perhaps be centralized to rpmsack
     try:
-        idx = ts.dbMatch('provides', distroverpkg)
+        matches = rpmdb.searchProvides(distroverpkg)
     except TypeError, e:
         # This is code for "cannot open rpmdb"
         # this is for pep 352 compliance on python 2.6 and above :(
@@ -1018,14 +1019,10 @@ def _getsysver(installroot, distroverpkg):
         raise Errors.YumBaseError("Error: " + str(e))
     # we're going to take the first one - if there is more than one of these
     # then the user needs a beating
-    if idx.count() == 0:
+    if not matches:
         releasever = '$releasever'
     else:
-        hdr = idx.next()
-        releasever = hdr['version']
-        del hdr
-    del idx
-    del ts
+        releasever = matches[0].version
     return releasever
 
 def writeRawRepoFile(repo,only=None):
-- 
1.7.4



More information about the Yum-devel mailing list