[yum-cvs] 2 commits - yum/packages.py

James Antill james at linux.duke.edu
Wed Dec 12 00:34:49 UTC 2007


 yum/packages.py |   30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

New commits:
commit 616141b3a263097a6a3efac8d331b471aa6f8e5b
Author: James Antill <james at and.org>
Date:   Tue Dec 11 19:34:37 2007 -0500

    Make parsePackages() faster for common case

diff --git a/yum/packages.py b/yum/packages.py
index add3afd..207ef37 100644
--- a/yum/packages.py
+++ b/yum/packages.py
@@ -92,7 +92,26 @@ def parsePackages(pkgs, usercommands, casematch=0):
                 return True
         return False
 
-    pkgdict = buildPkgRefDict(pkgs, bool(casematch))
+    # If we can match on only the name, do so as it uses much less CPU/RAM
+    # for the pkgdict. And most of the time poepl use: foo or foo*
+    name_only_match = True
+    for command in usercommands:
+        if command[-1] == '*': # Can still match on name only, for prefix
+            command = command[:-1]
+        if contains(command, "*,[]{}?.-"):
+            name_only_match = False
+            break
+
+    if not name_only_match:
+        pkgdict = buildPkgRefDict(pkgs, bool(casematch))
+    else:
+        pkgdict = {}
+        for pkg in pkgs:
+            n = pkg.name
+            if not casematch:
+                n = n.lower()
+            pkgdict.setdefault(n, []).append(pkg)
+
     exactmatch = []
     matched = []
     unmatched = []
commit 4dde3792ec7589c64130186cd784faef652d7a1f
Author: James Antill <james at and.org>
Date:   Tue Dec 11 19:31:20 2007 -0500

    Make wildcard test more readable

diff --git a/yum/packages.py b/yum/packages.py
index f682140..add3afd 100644
--- a/yum/packages.py
+++ b/yum/packages.py
@@ -85,6 +85,13 @@ def parsePackages(pkgs, usercommands, casematch=0):
        takes an optional casematch option to determine if case should be matched
        exactly. Defaults to not matching."""
 
+    def contains(haystack, needle):
+        """ If anything from needle is in haystack, return True. """
+        for x in needle:
+            if x in haystack:
+                return True
+        return False
+
     pkgdict = buildPkgRefDict(pkgs, bool(casematch))
     exactmatch = []
     matched = []
@@ -98,7 +105,7 @@ def parsePackages(pkgs, usercommands, casematch=0):
         else:
             # anything we couldn't find a match for
             # could mean it's not there, could mean it's a wildcard
-            if re.match('.*[\*,\[,\],\{,\},\?].*', command):
+            if contains(command, "*,[]{}?"):
                 trylist = pkgdict.keys()
                 # command and pkgdict are already lowered if not casematch
                 # so case sensitive is always fine



More information about the Yum-cvs-commits mailing list