[yum-cvs] yum/yum __init__.py,1.147,1.148 packages.py,1.38,1.39

Seth Vidal skvidal at login.linux.duke.edu
Sun Nov 13 11:02:51 UTC 2005


Update of /home/groups/yum/cvs/yum/yum
In directory login:/tmp/cvs-serv19534/yum

Modified Files:
	__init__.py packages.py 
Log Message:

- doGenericSetup() takes a cache argument so it can be used by non-root
users
- remove several duplicate functions from packages.py
- make install() handle multilib correctly


Index: __init__.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/__init__.py,v
retrieving revision 1.147
retrieving revision 1.148
diff -u -r1.147 -r1.148
--- __init__.py	8 Nov 2005 06:33:05 -0000	1.147
+++ __init__.py	13 Nov 2005 11:02:49 -0000	1.148
@@ -43,7 +43,7 @@
 import plugins
 
 
-from packages import parsePackages, YumLocalPackage, YumInstalledPackage, bestPackage
+from packages import parsePackages, YumLocalPackage, YumInstalledPackage
 from repomd import mdErrors
 from constants import *
 from repomd.packageSack import ListPackageSack
@@ -77,11 +77,12 @@
     def filelog(self, value, msg):
         print msg
    
-    def doGenericSetup(self):
+    def doGenericSetup(self, cache=0):
         """do a default setup for all the normal/necessary yum components,
            really just a shorthand for testing"""
         
         self.doConfigSetup()
+        self.conf.cache = cache
         self.doTsSetup()
         self.doRpmDBSetup()
         self.doRepoSetup()
@@ -1276,11 +1277,12 @@
         for pkg in pkgs:
             self.log(5, 'Adding package %s from group %s' % (pkg, thisgroup.groupid))
             try:
-                txmbr = self.install(name = pkg)
+                txmbrs = self.install(name = pkg)
             except Errors.InstallError, e:
                 self.log(3, 'No package named %s available to be installed' % pkg)
             else:
-                txmbr.groups.append(thisgroup.groupid)
+                for txmbr in txmbrs:
+                    txmbr.groups.append(thisgroup.groupid)
 
     def deselectGroup(self, grpid):
         """de-mark all the packages in the group for install"""
@@ -1419,42 +1421,11 @@
         except Errors.YumBaseError, e:
             raise Errors.YumBaseError, 'No Package found for %s' % depstring
         
-        result = self.bestPackageFromList(pkglist)
+        result = self._bestPackageFromList(pkglist)
         if result is None:
             raise Errors.YumBaseError, 'No Package found for %s' % depstring
         
         return result
-        
-    def bestPackageFromList(self, pkglist):
-        """take list of package objects and return the best package object.
-           If the list is empty, raise Errors.YumBaseError"""
-        
-        
-        if len(pkglist) == 0:
-            return None
-            
-        if len(pkglist) == 1:
-            return pkglist[0]
-        
-        mysack = ListPackageSack()
-        mysack.addList(pkglist)
-        bestlist = mysack.returnNewestByNameArch() # get rid of all lesser vers
-        
-        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
-
-            # compare arch
-            arch = rpmUtils.arch.getBestArchFromList([pkg.arch, best.arch])
-            if arch == pkg.arch:
-                best = pkg
-                continue
-
-        return best
 
     def returnInstalledPackagesByDep(self, depstring):
         """Pass in a generic [build]require string and this function will 
@@ -1488,14 +1459,78 @@
         
         return results
 
+
+    def _bestPackageFromList(self, pkglist):
+        """take list of package objects and return the best package object.
+           If the list is empty, return None. 
+           
+           Note: this is not aware of multilib so make sure you're only
+           passing it packages of a single arch group."""
+        
+        
+        if len(pkglist) == 0:
+            return None
+            
+        if len(pkglist) == 1:
+            return pkglist[0]
+        
+        mysack = ListPackageSack()
+        mysack.addList(pkglist)
+        bestlist = mysack.returnNewestByNameArch() # get rid of all lesser vers
+        
+        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
+
+            # compare arch
+            arch = rpmUtils.arch.getBestArchFromList([pkg.arch, best.arch])
+            if arch == pkg.arch:
+                best = pkg
+                continue
+
+        return best
+
+    def bestPackagesFromList(self, pkglist, arch=None):
+        """Takes a list of packages, returns the best packages.
+           This function is multilib aware so that it will not compare
+           multilib to singlelib packages""" 
+    
+        returnlist = []
+        compatArchList = rpmUtils.arch.getArchList(arch)
+        multiLib = []
+        singleLib = []
+        for po in pkglist:
+            if po.arch not in compatArchList:
+                continue
+            elif rpmUtils.arch.isMultiLibArch(arch=po.arch):
+                multiLib.append(po)
+            else:
+                singleLib.append(po)
+                
+        # we should have two lists now - one of singleLib packages
+        # one of multilib packages
+        # go through each one and find the best package(s)
+        for pkglist in [multiLib, singleLib]:
+            best = self._bestPackageFromList(pkglist)
+            if best is not None:
+                returnlist.append(best)
+        
+        return returnlist
+
+
     def install(self, po=None, **kwargs):
         """try to mark for install the item specified. Uses provided package 
            object, if available. If not it uses the kwargs and gets the best
-           package from the keyword options provided
-           returns the txmbr of the item it installed.
+           packages from the keyword options provided 
+           returns the list of txmbr of the items it installs
            
-           Note: This function will only ever install a single item at a time"""
+           """
         
+        pkgs = []
         if po is None:
             if not hasattr(self, 'pkgSack'):
                 self.doRepoSetup()
@@ -1522,23 +1557,30 @@
 
             pkgs = self.pkgSack.searchNevra(name=name, epoch=epoch, arch=arch,
                     ver=version, rel=release)
+            
             if pkgs:
-                po = self.bestPackageFromList(pkgs)
+                pkgs = self.bestPackagesFromList(pkgs)
 
-        if po is None:
+        if len(pkgs) == 0:
             raise Errors.InstallError, 'No package available to install'
         
         # FIXME - lots more checking here
         #  - update instead
         #  - install instead of erase
         #  - better exceptions
-        txmbrs = self.tsInfo.getMembers(pkgtup=po.pkgtup)
-        if txmbrs:
-            self.log(4, 'Package: %s  - already in transaction set' % po)
-            return txmbrs[0]
-        else:
-            txmbr = self.tsInfo.addInstall(po)
-            return txmbr
+        
+        tx_return = []
+        for po in pkgs:
+            txmbrs = self.tsInfo.getMembers(pkgtup=po.pkgtup)
+            if txmbrs:
+                self.log(4, 'Package: %s  - already in transaction set' % po)
+                tx_return.extend(txmbrs)
+                
+            else:
+                txmbr = self.tsInfo.addInstall(po)
+                tx_return.append(txmbr)
+        
+        return tx_return
 
     
     def update(self, input):

Index: packages.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/packages.py,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- packages.py	27 Oct 2005 05:32:13 -0000	1.38
+++ packages.py	13 Nov 2005 11:02:49 -0000	1.39
@@ -105,67 +105,6 @@
     return exactmatch, matched, unmatched
 
 
-def returnBestPackages(pkgdict, arch=None):
-    """returns a list of package tuples that are the 'best' packages for this
-       arch. Best == highest version and best scoring/sorting arch
-       should consider multiarch separately"""
-    returnlist = []
-    compatArchList = rpmUtils.arch.getArchList(arch)
-    for pkgname in pkgdict.keys():
-        # go through the packages, pitch out the ones that can't be used
-        # on this system at all
-        pkglist = pkgdict[pkgname]
-        uselist = []
-        multiLib = []
-        singleLib = []
-        for pkg in pkglist:
-            (n, a, e, v, r) = pkg
-            if a not in compatArchList:
-                continue
-            elif rpmUtils.arch.isMultiLibArch(arch=a):
-                multiLib.append(pkg)
-            else:
-                singleLib.append(pkg)
-        # we should have two lists now - one of singleLib packages
-        # one of multilib packages
-        # go through each one and find the best package(s)
-        for pkglist in [multiLib, singleLib]:
-            if len(pkglist) > 0:
-                best = pkglist[0]
-            else:
-                continue
-            for pkg in pkglist[1:]:
-                best = bestPackage(best, pkg)
-            if best is not None:
-                returnlist.append(best)
-    
-    return returnlist
-
-def bestPackage(pkg1, pkg2):
-    """compares two package tuples (assumes the names are the same), and returns
-       the one with the best version and the best arch, the sorting is:
-       for compatible arches, the highest version is best so:
-       foo-1.1-1.i686 is better than foo-1.1-1.i386 on an i686 machine
-       but foo-1.2-1.alpha is not better than foo-1.1-1.i386 on an i686
-       machine and foo-1.3-1.i386 is better than foo-1.1-1.i686 on an i686
-       machine."""
-    (n1, a1, e1, v1, r1) = pkg1
-    (n2, a2, e2, v2, r2) = pkg2
-    rc = rpmUtils.miscutils.compareEVR((e1, v1, r1), (e2, v2, r2))
-    if rc == 0:
-        # tiebreaker
-        bestarch = rpmUtils.arch.getBestArchFromList([a1, a2])
-        if bestarch is None: # how the hell did this happen?
-            return None
-        if bestarch == a1:
-            return pkg1
-        if bestarch == a2:
-            return pkg2
-    elif rc > 0:
-        return pkg1
-    elif rc < 0:
-        return pkg2
-    
 # goal for the below is to have a packageobject that can be used by generic
 # functions independent of the type of package - ie: installed or available
 




More information about the Yum-cvs-commits mailing list