[yum-cvs] 2 commits - yum/packages.py yum/sqlitesack.py
James Antill
james at linux.duke.edu
Tue Dec 11 17:01:02 UTC 2007
yum/packages.py | 30 ++++++++++--------------------
yum/sqlitesack.py | 37 +++++++++++++++++++------------------
2 files changed, 29 insertions(+), 38 deletions(-)
New commits:
commit 84e26e7cf43716c591ad2139e21f947090c626f9
Author: James Antill <james at and.org>
Date: Tue Dec 11 12:00:56 2007 -0500
Make parsePackages() faster, add casematch argument to buildPkgRefDict().
diff --git a/yum/packages.py b/yum/packages.py
index 900d9a1..0a135f9 100644
--- a/yum/packages.py
+++ b/yum/packages.py
@@ -44,7 +44,7 @@ def comparePoEVR(po1, po2):
(e2, v2, r2) = (po2.epoch, po2.version, po2.release)
return rpmUtils.miscutils.compareEVR((e1, v1, r1), (e2, v2, r2))
-def buildPkgRefDict(pkgs):
+def buildPkgRefDict(pkgs, casematch=True):
"""take a list of pkg objects and return a dict the contains all the possible
naming conventions for them eg: for (name,i386,0,1,1)
dict[name] = (name, i386, 0, 1, 1)
@@ -58,6 +58,8 @@ def buildPkgRefDict(pkgs):
pkgdict = {}
for pkg in pkgs:
(n, a, e, v, r) = pkg.pkgtup
+ if not casematch:
+ n = n.lower()
name = n
nameArch = '%s.%s' % (n, a)
nameVerRelArch = '%s-%s-%s.%s' % (n, v, r, a)
@@ -79,11 +81,13 @@ def parsePackages(pkgs, usercommands, casematch=0):
takes an optional casematch option to determine if case should be matched
exactly. Defaults to not matching."""
- pkgdict = buildPkgRefDict(pkgs)
+ pkgdict = buildPkgRefDict(pkgs, bool(casematch))
exactmatch = []
matched = []
unmatched = []
for command in usercommands:
+ if not casematch:
+ command = command.lower()
if pkgdict.has_key(command):
exactmatch.extend(pkgdict[command])
del pkgdict[command]
@@ -92,11 +96,10 @@ def parsePackages(pkgs, usercommands, casematch=0):
# could mean it's not there, could mean it's a wildcard
if re.match('.*[\*,\[,\],\{,\},\?].*', command):
trylist = pkgdict.keys()
+ # command and pkgdict are already lowered if not casematch
+ # so case sensitive is always fine
restring = fnmatch.translate(command)
- if casematch:
- regex = re.compile(restring) # case sensitive
- else:
- regex = re.compile(restring, flags=re.I) # case insensitive
+ regex = re.compile(restring)
foundit = 0
for item in trylist:
if regex.match(item):
@@ -108,20 +111,7 @@ def parsePackages(pkgs, usercommands, casematch=0):
unmatched.append(command)
else:
- if casematch:
- unmatched.append(command)
- else:
- # look for case insensitively
- foundit = 0
- for item in pkgdict.keys():
- if command.lower() == item.lower():
- matched.extend(pkgdict[item])
- foundit = 1
- continue
-
- # we got nada
- if not foundit:
- unmatched.append(command)
+ unmatched.append(command)
matched = misc.unique(matched)
unmatched = misc.unique(unmatched)
commit c01396a9703efaa8a1716f993112cd337b49231d
Author: James Antill <james at and.org>
Date: Tue Dec 11 11:25:05 2007 -0500
Stop rebuilding returnPackages when we don't need to
diff --git a/yum/sqlitesack.py b/yum/sqlitesack.py
index 1e72f92..47f0607 100644
--- a/yum/sqlitesack.py
+++ b/yum/sqlitesack.py
@@ -257,10 +257,9 @@ class YumSqlitePackageSack(yumRepo.YumPackageSack):
yumRepo.YumPackageSack.close(self)
def buildIndexes(self):
- # we just need to nuke the indexes first
- if hasattr(self, 'pkgobjlist'):
- del self.pkgobjlist
- self.returnPackages()
+ # We don't need to play with returnPackages() caching as it handles
+ # additions to excludes after the cache is built.
+ pass
def _checkIndexes(self, failure='error'):
return
@@ -750,31 +749,33 @@ class YumSqlitePackageSack(yumRepo.YumPackageSack):
return exactmatch, matched, unmatched
@catchSqliteException
- def returnPackages(self, repoid=None):
- """Returns a list of packages, only containing nevra information """
+ def _buildPkgObjList(self, repoid=None):
+ """Builds a list of packages, only containing nevra information. No
+ excludes are done at this stage. """
returnList = []
- if hasattr(self, 'pkgobjlist'):
- if self.pkgobjlist:
- for po in self.pkgobjlist:
- if self._excluded(po.repo, po.pkgId):
- continue
- returnList.append(po)
- return returnList
-
for (repo,cache) in self.primarydb.items():
if (repoid == None or repoid == repo.id):
cur = cache.cursor()
executeSQL(cur, "select pkgId,name,epoch,version,release,arch from packages")
for x in cur:
- if self._excluded(repo,x['pkgId']):
- continue
-
returnList.append(self.pc(repo,x))
-
self.pkgobjlist = returnList
+
+ def returnPackages(self, repoid=None):
+ """Returns a list of packages, only containing nevra information. The
+ packages are processed for excludes. """
+ returnList = []
+ if not hasattr(self, 'pkgobjlist'):
+ self._buildPkgObjList(repoid)
+
+ for po in self.pkgobjlist:
+ if self._excluded(po.repo, po.pkgId):
+ continue
+ returnList.append(po)
+
return returnList
@catchSqliteException
More information about the Yum-cvs-commits
mailing list