[yum-cvs] yum/yum __init__.py,1.126,1.127
Seth Vidal
skvidal at login.linux.duke.edu
Thu Jun 23 04:11:12 UTC 2005
Update of /home/groups/yum/cvs/yum/yum
In directory login:/tmp/cvs-serv9707/yum
Modified Files:
__init__.py
Log Message:
change out returnPackageByDep() to use returnPackagesByDep() and
bestPackageFromList() rather than duplicating a lot of simple code
Index: __init__.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/__init__.py,v
retrieving revision 1.126
retrieving revision 1.127
diff -u -r1.126 -r1.127
--- __init__.py 21 Jun 2005 12:22:27 -0000 1.126
+++ __init__.py 23 Jun 2005 04:11:10 -0000 1.127
@@ -41,10 +41,11 @@
import depsolve
import plugins
+
from packages import parsePackages, YumLocalPackage, YumInstalledPackage, bestPackage
from repomd import mdErrors
from constants import *
-
+from repomd.packageSack import ListPackageSack
__version__ = '2.3.3'
@@ -1266,10 +1267,11 @@
del fo
return 1
- def returnPackageByDep(self, depstring):
+ def returnPackagesByDep(self, depstring):
"""Pass in a generic [build]require string and this function will
- pass back the best(or first) package it finds providing that dep."""
+ pass back the packages it finds providing that dep."""
+ results = []
self.doRepoSetup()
# parse the string out
# either it is 'dep (some operator) e:v-r'
@@ -1285,65 +1287,51 @@
try:
depname, flagsymbol, depver = depstring.split()
except ValueError, e:
- raise Errors.YumBaseError, 'No Packages found for %s - have you tried quoting the string?' % depstring
+ raise Errors.YumBaseError, 'Invalid versioned dependency string, try quoting it.'
if not SYMBOLFLAGS.has_key(flagsymbol):
- raise Errors.YumBaseError, 'No Packages found for %s' % depstring
+ raise Errors.YumBaseError, 'Invalid version flag'
depflags = SYMBOLFLAGS[flagsymbol]
sack = self.whatProvides(depname, depflags, depver)
- if len(sack) < 1:
- raise Errors.YumBaseError, 'No Packages found for %s' % depstring
-
- if len(sack) == 1:
- for po in sack:
- return po
+ results = sack.returnPackages()
+ return results
- pkglist = sack.returnNewestByNameArch()
- best = pkglist[0]
- for pkg in pkglist[1:]:
- if len(pkg.name) < len(best.name): # shortest name silliness
- best = pkg
- continue
- elif len(pkg.name) > len(best.name):
- continue
- # compare arch
- arch = rpmUtils.arch.getBestArchFromList([pkg.arch, best.arch])
- if arch == pkg.arch:
- best = pkg
- continue
+ def returnPackageByDep(self, depstring):
+ """Pass in a generic [build]require string and this function will
+ pass back the best(or first) package it finds providing that dep."""
+
+ try:
+ pkglist = self.returnPackagesByDep(depstring)
+ except Errors.YumBaseError, e:
+ raise Errors.YumBaseError, 'No Package found for %s' % depstring
+
+
+ return self.bestPackageFromList(pkglist)
- return best
-
def bestPackageFromList(self, pkglist):
"""take list of package objects and return the best package object.
If the list is empty, raise Errors.YumBaseError"""
- # duh
if len(pkglist) == 1:
- for po in pkglist:
- return po
+ return pkglist[0]
+
+ mysack = ListPackageSack()
+ bestlist = mysack.returnNewestByNameArch() # get rid of all lesser vers
- best = pkglist[0]
- for pkg in pkglist[1:]:
+ best = bestlist[0]
+ for pkg in bestlist[1:]:
if len(pkg.name) < len(best.name): # shortest name silliness
best = pkg
continue
elif len(pkg.name) > len(best.name):
continue
- else:
- if pkg.name == best.name:
- bestup = bestPackage(pkg.pkgtup, best.pkgtup)
- if best.pkgtup == bestup:
- continue
- elif pkg.pkgtup == bestup:
- best = pkg
- continue
- else:
- mylist=[best, pkg]
- mylist.sort(cmp=self.sortPkgObj) # first name, alphabetically
- best = mylist[0]
- continue
+
+ # compare arch
+ arch = rpmUtils.arch.getBestArchFromList([pkg.arch, best.arch])
+ if arch == pkg.arch:
+ best = pkg
+ continue
return best
-
+
More information about the Yum-cvs-commits
mailing list