[yum-cvs] yum/yum packageSack.py,1.13,1.14 sqlitesack.py,1.41,1.42
Seth Vidal
skvidal at linux.duke.edu
Tue Aug 29 06:47:49 UTC 2006
Update of /home/groups/yum/cvs/yum/yum
In directory login1.linux.duke.edu:/tmp/cvs-serv26960/yum
Modified Files:
packageSack.py sqlitesack.py
Log Message:
- typo in sqlitesack that made it all break
- change out matchPackages for matchPackageNames() as that's what it is
doing
- convert to a generator for memory use
- simplify what it does
Index: packageSack.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/packageSack.py,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- packageSack.py 28 Aug 2006 12:45:03 -0000 1.13
+++ packageSack.py 29 Aug 2006 06:47:47 -0000 1.14
@@ -136,8 +136,8 @@
def searchPackages(self, fields, criteria_re, callback):
raise NotImplementedError()
- def matchPackages(self, matchlist, casematch=False):
- """take a list of user strings and match the packages in the sack against it
+ def matchPackageNames(self, input, casematch=False):
+ """take a user strings and match the packages in the sack against it
this will match against:
name
name.arch
@@ -147,22 +147,19 @@
epoch:name-ver-rel.arch
name-epoch:ver-rel.arch
- it returns 3 lists exactmatch, matched, unmatched
- exactmatch = package objects matching exactly to the specified input (using no globs)
- matched = package objects matching via globs
- unmatched = user input that matched nothing
-
- Arguments:
- matchlist: list
- list of things to match
+ 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
"""
- pkgdict = {}
# get everything together
+ thisdict = {}
for pkgtup in self.simplePkgList():
(n,a,e,v,r) = pkgtup
name = n
@@ -172,57 +169,39 @@
nameVerRel = '%s-%s-%s' % (n, v, r)
envra = '%s:%s-%s-%s.%s' % (e, n, v, r, a)
nevra = '%s-%s:%s-%s.%s' % (n, e, v, r, a)
- for item in [name, nameArch, nameVerRelArch, nameVer, nameVerRel, envra, nevra]:
- if not pkgdict.has_key(item):
- pkgdict[item] = []
- pkgdict[item].append(pkgtup)
-
+ for item in (name, nameArch, nameVerRelArch, nameVer,
+ nameVerRel, envra, nevra):
+ if not thisdict.has_key(item):
+ thisdict[item] = []
+ thisdict[item].append(pkgtup)
+
# match it up
- exactmatch = []
- matched = []
- unmatched = []
- for input in matchlist:
- if pkgdict.has_key(input):
- for matchtup in pkgdict[input]:
- exactmatch.extend(self.searchPkgTuple(matchtup))
- del pkgdict[input]
- else:
- # anything we couldn't find a match for
- # could mean it's not there, could mean it's a wildcard
- if re.match('.*[\*,\[,\],\{,\},\?].*', input):
- trylist = pkgdict.keys()
- restring = fnmatch.translate(input)
- if casematch:
- regex = re.compile(restring) # case sensitive
- else:
- regex = re.compile(restring, flags=re.I) # case insensitive
- foundit = 0
- for item in trylist:
- if regex.match(item):
- for matchtup in pkgdict[item]:
- matched.extend(self.searchPkgTuple(matchtup))
- del pkgdict[item]
- foundit = 1
-
- if not foundit:
- unmatched.append(input)
-
+ if thisdict.has_key(input):
+ for matchtup in thisdict[input]:
+ for po in self.searchPkgTuple(matchtup):
+ yield po
+
+ else:
+ # anything we couldn't find a match for
+ # could mean it's not there, could mean it's a wildcard
+ if re.match('.*[\*,\[,\],\{,\},\?].*', input):
+ restring = fnmatch.translate(input)
+ if casematch:
+ regex = re.compile(restring) # case sensitive
else:
- # we got nada
- unmatched.append(input)
-
- matched = misc.unique(matched)
- unmatched = misc.unique(unmatched)
- exactmatch = misc.unique(exactmatch)
-
- # fixme - maybe return a minor object that has:
- # foo = holderclass
- # foo.pkg
- # foo.matchedwith
- # foo.exactmatch
- # then let the user create the unmatched list themselves.
-
- return exactmatch, matched, unmatched
+ regex = re.compile(restring, flags=re.I) # case insensitive
+
+ trylist = thisdict.keys()
+ tmp_matches = {}
+ for item in trylist: # go through each one of the keys
+ if regex.match(item): # attempt to match the regex to it
+ for matchtup in thisdict[item]:
+ tmp_matches[matchtup] = 1
+
+ #for uniqueness
+ for matchtup in tmp_matches.keys():
+ for po in self.searchPkgTuple(matchtup):
+ yield po
class MetaSack(PackageSackBase):
Index: sqlitesack.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/sqlitesack.py,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -r1.41 -r1.42
--- sqlitesack.py 29 Aug 2006 05:17:54 -0000 1.41
+++ sqlitesack.py 29 Aug 2006 06:47:47 -0000 1.42
@@ -55,7 +55,7 @@
'buildhost' : 'rpm_buildhost',
'sourcerpm' : 'rpm_sourcerpm',
'vendor' : 'rpm_vendor',
- 'license', : 'rpm_license'
+ 'license' : 'rpm_license'
}
if not self.simple.has_key(varname):
dbname = varname
More information about the Yum-cvs-commits
mailing list