[yum-commits] Branch 'yum-3_2_X' - 2 commits - yum/depsolve.py yum/__init__.py yum/misc.py yum/packageSack.py yum/rpmsack.py yum/sqlitesack.py

skvidal at osuosl.org skvidal at osuosl.org
Tue Feb 16 03:04:16 UTC 2010


 yum/__init__.py    |   25 --------------------
 yum/depsolve.py    |   25 --------------------
 yum/misc.py        |   35 ++++++++++++++++++++++++++++
 yum/packageSack.py |   66 +++++++++++++++++++++++++++++------------------------
 yum/rpmsack.py     |    9 ++++---
 yum/sqlitesack.py  |   38 +++++++++++++++++++++++-------
 6 files changed, 109 insertions(+), 89 deletions(-)

New commits:
commit 23b461a43c546d969d9150b7169437e44730c086
Merge: 2dcc612... ca1b546...
Author: Seth Vidal <skvidal at fedoraproject.org>
Date:   Mon Feb 15 19:36:12 2010 -0500

    Merge branch 'yum-3_2_X' of ssh://yum.baseurl.org/srv/projects/yum/git/yum into yum-3_2_X
    
    * 'yum-3_2_X' of ssh://yum.baseurl.org/srv/projects/yum/git/yum:
      l10n: Updates to Spanish (Castilian) (es) translation
      l10n: Updates to Italian (it) translation
      l10n: Updates to Polish (pl) translation
      l10n: Updates to Finnish (fi) translation

commit 2dcc61234082552adc91aaf440a9a43ce5b77fab
Author: Seth Vidal <skvidal at fedoraproject.org>
Date:   Mon Feb 15 19:33:14 2010 -0500

    - make searchPrco do completely specific results - not just matches against name
    
    - this required fixing a lot of code but the results are now more correct and whatProvides() is
      dramatically reduced in terms of what it does.
    - adds searchPrco to the PackageSack object
    - adds misc.string_to_prco_tuple() which combines the partial conversions of 'foo > 1.1' that
      returnPackagesByDep() and whatProvides() had been doing, badly.
      this is also a reversal of misc.prco_tuple_to_string()

diff --git a/yum/__init__.py b/yum/__init__.py
index 096268e..06f6156 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -2592,30 +2592,7 @@ class YumBase(depsolve.Depsolve):
         """Pass in a generic [build]require string and this function will 
            pass back the packages it finds providing that dep."""
         
-        results = []
-        # parse the string out
-        #  either it is 'dep (some operator) e:v-r'
-        #  or /file/dep
-        #  or packagename
-        # or a full dep tuple
-        if type(depstring) == types.TupleType:
-            (depname, depflags, depver) = depstring
-        else:
-            depname = depstring
-            depflags = None
-            depver = None
-        
-            if depstring[0] != '/':
-                # not a file dep - look at it for being versioned
-                dep_split = depstring.split()
-                if len(dep_split) == 3:
-                    depname, flagsymbol, depver = dep_split
-                    if not flagsymbol in SYMBOLFLAGS:
-                        raise Errors.YumBaseError, _('Invalid version flag')
-                    depflags = SYMBOLFLAGS[flagsymbol]
-                
-        sack = self.whatProvides(depname, depflags, depver)
-        results = sack.returnPackages()
+        results = self.pkgSack.searchProvides(depstring)
         return results
         
 
diff --git a/yum/depsolve.py b/yum/depsolve.py
index c1e90c5..11c9f29 100644
--- a/yum/depsolve.py
+++ b/yum/depsolve.py
@@ -158,30 +158,7 @@ class Depsolve(object):
 
         self.verbose_logger.log(logginglevels.DEBUG_1, _('Searching pkgSack for dep: %s'),
             name)
-        pkgs = self.pkgSack.searchProvides(name)
-        
-        
-        if flags == 0:
-            flags = None
-        if type(version) in (types.StringType, types.NoneType, types.UnicodeType):
-            (r_e, r_v, r_r) = rpmUtils.miscutils.stringToVersion(version)
-        elif type(version) in (types.TupleType, types.ListType): # would this ever be a ListType?
-            (r_e, r_v, r_r) = version
-        
-        defSack = ListPackageSack() # holder for items definitely providing this dep
-        
-        for po in pkgs:
-            self.verbose_logger.log(logginglevels.DEBUG_2,
-                _('Potential match for %s from %s'), name, po)
-            if misc.re_filename(name) and r_v is None:
-                # file dep add all matches to the defSack
-                defSack.addPackage(po)
-                continue
-
-            if po.checkPrco('provides', (name, flags, (r_e, r_v, r_r))):
-                defSack.addPackage(po)
-                self.verbose_logger.debug(_('Matched %s to require for %s'), po, name)
-        
+        defSack = ListPackageSack(self.pkgSack.searchProvides((name, flags, version)))
         return defSack
         
     def allowedMultipleInstalls(self, po):
diff --git a/yum/misc.py b/yum/misc.py
index d63993b..6d325bf 100644
--- a/yum/misc.py
+++ b/yum/misc.py
@@ -11,6 +11,7 @@ import struct
 import re
 import errno
 import Errors
+import constants
 import pgpmsg
 import tempfile
 import glob
@@ -18,6 +19,7 @@ import pwd
 import fnmatch
 import bz2
 import gzip
+from rpmUtils.miscutils import stringToVersion, flagToString
 from stat import *
 try:
     import gpgme
@@ -628,7 +630,40 @@ def prco_tuple_to_string(prcoTuple):
         return name
     
     return '%s %s %s' % (name, flags[flag], version_tuple_to_string(evr))
+
+def string_to_prco_tuple(prcoString):
+    """returns a prco tuple (name, flags, (e, v, r)) for a string"""
+
+    if type(prcoString) == types.TupleType:
+        (n, f, v) = prcoString
+    else:
+        n = prcoString
+        f = v = None
+        
+        if n[0] != '/':
+            # not a file dep - look at it for being versioned
+            prco_split = n.split()
+            if len(prco_split) == 3:
+                n, f, v = prco_split
     
+    # now we have 'n, f, v' where f and v could be None and None
+    if f is not None:
+        if f not in constants.SYMBOLFLAGS:
+            try:
+                f = flagToString(int(f))
+            except TypeError, e:
+                raise Errors.MiscError, 'Invalid version flag: %s' % f
+        else:
+            f = constants.SYMBOLFLAGS[f]
+
+    if type(v) in (types.StringType, types.NoneType, types.UnicodeType):
+        (prco_e, prco_v, prco_r) = stringToVersion(v)
+    elif type(v) in (types.TupleType, types.ListType):
+        (prco_e, prco_v, prco_r) = v
+    
+    #now we have (n, f, (e, v, r)) for the thing specified
+    return (n, f, (prco_e, prco_v, prco_r))
+
 def refineSearchPattern(arg):
     """Takes a search string from the cli for Search or Provides
        and cleans it up so it doesn't make us vomit"""
diff --git a/yum/packageSack.py b/yum/packageSack.py
index 95b278a..6e986a4 100644
--- a/yum/packageSack.py
+++ b/yum/packageSack.py
@@ -702,42 +702,50 @@ class PackageSack(PackageSackBase):
                 result[po] = hits
         return result
 
+    def searchPrco(self, name, prcotype):
+        self._checkIndexes(failure='build')
+        prcodict = getattr(self, prcotype)
+        (n,f,(e,v,r)) = misc.string_to_prco_tuple(name)
+        
+        basic_results = []
+        results = []
+        if n in prcodict:
+            basic_results.extend(prcodict[n])
+
+        for po in basic_results:
+            if po.checkPrco(prcotype, (n, f, (e,v,r))):
+                results.append(po)
+
+        if prcotype != "provides":
+            return results
+            
+        if not misc.re_filename(n):
+            return results
+
+        results.extend(self.searchFiles(n))
+        return misc.unique(results)
+
+            
     def searchRequires(self, name):
-        """return list of package requiring the name (any evr and flag)"""
-        self._checkIndexes(failure='build')        
-        if self.requires.has_key(name):
-            return self.requires[name]
-        else:
-            return []
+        """return list of package requiring the item requested"""
+
+        return self.searchPrco(name, 'requires')
 
     def searchProvides(self, name):
-        """return list of package providing the name (any evr and flag)"""
-        # FIXME - should this do a pkgobj.checkPrco((name, flag, (e,v,r,))??
-        # has to do a searchFiles and a searchProvides for things starting with /
-        self._checkIndexes(failure='build')        
-        returnList = []
-        if name[0] == '/':
-            returnList.extend(self.searchFiles(name))
-        if self.provides.has_key(name):
-            returnList.extend(self.provides[name])
-        return returnList
+        """return list of package providing the item requested"""
+        
+        return self.searchPrco(name, 'provides')
 
     def searchConflicts(self, name):
-        """return list of package conflicting with the name (any evr and flag)"""
-        self._checkIndexes(failure='build')        
-        if self.conflicts.has_key(name):
-            return self.conflicts[name]
-        else:
-            return []
-
+        """return list of package conflicting with item requested"""
+        
+        return self.searchPrco(name, 'conflicts')
+        
     def searchObsoletes(self, name):
-        """return list of package obsoleting the name (any evr and flag)"""
-        self._checkIndexes(failure='build')        
-        if self.obsoletes.has_key(name):
-            return self.obsoletes[name]
-        else:
-            return []
+        """return list of package obsoleting the item requested"""
 
+        return self.searchPrco(name, 'obsoletes')
+        
     def returnObsoletes(self, newest=False):
         """returns a dict of obsoletes dict[obsoleting pkgtuple] = [list of obs]"""
         obs = {}
diff --git a/yum/rpmsack.py b/yum/rpmsack.py
index b45f315..4ab20e9 100644
--- a/yum/rpmsack.py
+++ b/yum/rpmsack.py
@@ -282,18 +282,21 @@ class RPMDBPackageSack(PackageSackBase):
         result = self._cache[prcotype].get(name)
         if result is not None:
             return result
-
+        (n,f,(e,v,r)) = misc.string_to_prco_tuple(name)
+        
         ts = self.readOnlyTS()
         result = {}
         tag = self.DEP_TABLE[prcotype][0]
-        mi = ts.dbMatch(tag, misc.to_utf8(name))
+        mi = ts.dbMatch(tag, misc.to_utf8(n))
         for hdr in mi:
             if hdr['name'] == 'gpg-pubkey':
                 continue
             po = self._makePackageObject(hdr, mi.instance())
-            result[po.pkgid] = po
+            if po.checkPrco(prcotype, (n, f, (e,v,r))):
+                result[po.pkgid] = po
         del mi
 
+
         # If it's not a provides or filename, we are done
         if prcotype == 'provides' and name[0] == '/':
             fileresults = self.searchFiles(name)
diff --git a/yum/sqlitesack.py b/yum/sqlitesack.py
index 33c088c..6b9acfc 100644
--- a/yum/sqlitesack.py
+++ b/yum/sqlitesack.py
@@ -1263,38 +1263,58 @@ class YumSqlitePackageSack(yumRepo.YumPackageSack):
  
     @catchSqliteException
     def searchPrco(self, name, prcotype):
-        """return list of packages having prcotype name (any evr and flag)"""
+        """return list of packages matching name and prcotype """
+        # we take name to be a string of some kind
+        # we parse the string to see if it is a foo > 1.1 or if it is just 'foo'
+        # or what - so we can answer correctly
+        
         if self._skip_all():
             return []
+        try:
+            (n,f,(e,v,r)) = misc.string_to_prco_tuple(name)
+        except Errors.MiscError, e:
+            raise Errors.PackageSackError, to_unicode(e)
         
-        name = to_unicode(name)
+        n = to_unicode(n)
+
         glob = True
         querytype = 'glob'
-        if not misc.re_glob(name):
+        if not misc.re_glob(n):
             glob = False
             querytype = '='
 
+        basic_results = []
         results = []
         for (rep,cache) in self.primarydb.items():
             cur = cache.cursor()
-            executeSQL(cur, "select DISTINCT pkgKey from %s where name %s ?" % (prcotype,querytype), (name,))
-            self._sql_pkgKey2po(rep, cur, results)
+            executeSQL(cur, "select DISTINCT pkgKey from %s where name %s ?" % (prcotype,querytype), (n,))
+            self._sql_pkgKey2po(rep, cur, basic_results)
         
+        # now we have a list of items matching just the name - let's match them out
+        for po in basic_results:
+            if misc.re_filename(n) and v is None:
+                # file dep add all matches to the results
+                results.append(po)
+                continue
+
+            if po.checkPrco(prcotype, (n, f, (e,v,r))):
+                results.append(po)
+
         # If it's not a provides or a filename, we are done
         if prcotype != "provides":
             return results
-        if not misc.re_filename(name):
+        if not misc.re_filename(n):
             return results
 
         # If it is a filename, search the primary.xml file info
-        results.extend(self._search_primary_files(name))
+        results.extend(self._search_primary_files(n))
 
         # if its in the primary.xml files then skip the other check
-        if misc.re_primary_filename(name) and not glob:
+        if misc.re_primary_filename(n) and not glob:
             return misc.unique(results)
 
         # If it is a filename, search the files.xml file info
-        results.extend(self.searchFiles(name))
+        results.extend(self.searchFiles(n))
         return misc.unique(results)
         
         


More information about the Yum-commits mailing list