Jeremy Katz wrote:
On Tue, 2007-06-05 at 13:22 +0200, Florian Festi wrote:
    * adjusted interface of PackageSackBase.matchPackageNames()
      to other Sacks
     * Does this break anything?

This should be safe.  Or if it's not, it's already going to be breaking
things :)  But it's been like this since 3.0.x, so probably fine

Jeremy

Needed to allow PackageSackBase being part of a MetaSack. Patch attached

Florian
Index: yum/packageSack.py
===================================================================
RCS file: /cvsroot/yum/cvs/yum/yum/packageSack.py,v
retrieving revision 1.29
diff -u -r1.29 packageSack.py
--- yum/packageSack.py	4 Mar 2007 21:45:16 -0000	1.29
+++ yum/packageSack.py	6 Jun 2007 09:32:29 -0000
@@ -137,8 +137,8 @@
     def searchAll(self, arg, query_type):
         raise NotImplementedError()
     
-    def matchPackageNames(self, input, casematch=False):
-        """take a user strings and match the packages in the sack against it
+    def matchPackageNames(self, pkgspecs):
+        """take a list strings and match the packages in the sack against it
            this will match against:
            name
            name.arch
@@ -148,40 +148,24 @@
            epoch:name-ver-rel.arch
            name-epoch:ver-rel.arch
            
-           it yields a package object for each match
-
-            Arguments:
-             input: string
-               string to match
-             
-             casematch: Boolean
-                if true then match case sensitively
-                if false then match case insensitively
-                default False
+           return [exact matches], [glob matches], [unmatch search terms]
            """
         # Setup match() for the search we're doing
-        if re.search('[\*\[\]\{\}\?]', input):
-            restring = fnmatch.translate(input)
-            if casematch:
-                regex = re.compile(restring)             # case sensitive
-            else:
-                regex = re.compile(restring, flags=re.I) # case insensitive
-
-            def match(s):
-                return regex.match(s)
+        matched = []
+        exactmatch = []
+        unmatched = set(pkgspecs)
 
-        else:
-            if casematch:
-                def match(s):
-                    return s == input
+        specs = {}
+        for p in pkgspecs:
+            if re.search('[\*\[\]\{\}\?]', p):
+                restring = fnmatch.translate(p)
+                specs[p] = re.compile(restring)
             else:
-                input = input.lower()
-                def match(s):
-                    return s.lower() == input
+                specs[p] = p
          
         for pkgtup in self.simplePkgList():
             (n,a,e,v,r) = pkgtup
-            names = (
+            names = set((
                 n, 
                 '%s.%s' % (n, a),
                 '%s-%s-%s.%s' % (n, v, r, a),
@@ -189,13 +173,18 @@
                 '%s-%s-%s' % (n, v, r),
                 '%s:%s-%s-%s.%s' % (e, n, v, r, a),
                 '%s-%s:%s-%s.%s' % (n, e, v, r, a),
-                )
-            for name in names:
-                if match(name):
-                    for po in self.searchPkgTuple(pkgtup):
-                        yield po
-                    break       # Only match once per package
-
+                ))
+            for term, query in specs:
+                if term == query:
+                    if query in names:
+                        exactmatch.append(self.searchPkgTuple(pkgtup)[0])
+                        unmatched.discard(term)
+                else:
+                    for n in names:
+                        if query.match(n):
+                            matched.append(self.searchPkgTuple(pkgtup)[0])
+                            unmatched.discard(term)
+        return misc.unique(exactmatch), misc.unique(matched), list(unmatched)
 
 
 class MetaSack(PackageSackBase):
_______________________________________________
Yum-devel mailing list
[email protected]
https://lists.dulug.duke.edu/mailman/listinfo/yum-devel

Reply via email to