[yum-cvs] 2 commits - output.py yum/config.py yum/__init__.py yum/packages.py yum/transactioninfo.py yum/yumRepo.py

Seth Vidal skvidal at linux.duke.edu
Wed Sep 19 03:07:08 UTC 2007


 output.py              |   11 +++++-----
 yum/__init__.py        |   51 +++++++++++++++++++++++++++++++++++++++++++++++--
 yum/config.py          |    3 +-
 yum/packages.py        |    2 +
 yum/transactioninfo.py |    4 ++-
 yum/yumRepo.py         |    1 
 6 files changed, 63 insertions(+), 9 deletions(-)

New commits:
commit 6bf2e42c02db756ff208f14c447ca2fe369e119c
Merge: 5f55e93... 2ad0940...
Author: Seth Vidal <skvidal at fedoraproject.org>
Date:   Tue Sep 18 23:01:54 2007 -0400

    Merge branch 'master' of ssh://login.linux.duke.edu/home/groups/yum/git/yum
    
    * 'master' of ssh://login.linux.duke.edu/home/groups/yum/git/yum:
      sigmd5 isn't guaranteed to be there either.  this should be fine, though and
      capture scriptlet output via a pipe and pass it via a callback method on a

commit 5f55e931103be22da51d31f08f21b7f5fa20f1d4
Author: Seth Vidal <skvidal at fedoraproject.org>
Date:   Tue Sep 18 17:05:03 2007 -0400

    - yum search output a little nicer for users - suggestions from tech-list and james antill
    - implement cost feature per repo
    - fix up cases where callers don't properly call addUpdated() for pkgs being updated by a txmbr - problem comes out in skip-broken
      thanks to bill nottingham for the replicated bug

diff --git a/output.py b/output.py
index 8aff587..1f9afc1 100644
--- a/output.py
+++ b/output.py
@@ -240,12 +240,13 @@ class YumOutput:
         return(format % (number, space, symbols[depth]))
 
     def matchcallback(self, po, values):
-        self.verbose_logger.log(logginglevels.INFO_2, '\n\n')
-        self.simpleList(po)
-        self.verbose_logger.log(logginglevels.INFO_2, 'Matched from:')
+        msg = '%s.%s : %s' % (po.name, po.arch, po.summary)
+        self.verbose_logger.log(logginglevels.INFO_2, msg)
+        self.verbose_logger.debug('Matched from:')
         for item in values:
-            self.verbose_logger.log(logginglevels.INFO_2, '%s', item)
-
+            self.verbose_logger.debug('%s', item)
+        self.verbose_logger.debug('\n\n')
+        
     def reportDownloadSize(self, packages):
         """Report the total download size for a set of packages"""
         totsize = 0
diff --git a/yum/__init__.py b/yum/__init__.py
index 22d3d6a..fc1d483 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -381,19 +381,21 @@ class YumBase(depsolve.Depsolve):
         self.repos.populateSack(which=repos)
         self._pkgSack = self.repos.getPackageSack()
         
-        #FIXME - this is not very fast
         self.excludePackages()
         self._pkgSack.excludeArchs(archlist)
         
-        #FIXME - this could be faster, too.
         for repo in repos:
             self.excludePackages(repo)
             self.includePackages(repo)
         self.plugins.run('exclude')
         self._pkgSack.buildIndexes()
 
+        # now go through and kill pkgs based on pkg.repo.cost()
+        self.costExcludePackages()
+        
         return self._pkgSack
     
+    
     def _delSacks(self):
         """reset the package sacks back to zero - making sure to nuke the ones
            in the repo objects, too - where it matters"""
@@ -597,6 +599,51 @@ class YumBase(depsolve.Depsolve):
                         self.logger.critical('Failed to remove transaction file %s' % fn)
 
         self.plugins.run('posttrans')
+    
+    def costExcludePackages(self):
+        """exclude packages if they have an identical package in another repo
+        and their repo.cost value is the greater one"""
+        
+        # check to see if the cost per repo is anything other than equal
+        # if all the repo.costs are equal then don't bother running things
+        costs = {}
+        for r in self.repos.listEnabled():
+            costs[r.cost] = 1
+        
+        if len(costs.keys()) == 1: # if all of our costs are the same then return
+            return
+            
+        def _sort_by_cost(a, b):
+            if a.repo.cost < b.repo.cost:
+                return -1
+            if a.repo.cost == b.repo.cost:
+                return 0
+            if a.repo.cost > b.repo.cost:
+                return 1
+                
+        pkgdict = {}
+        for po in self.pkgSack:
+            if not pkgdict.has_key(po.pkgtup):
+                pkgdict[po.pkgtup] = []
+            pkgdict[po.pkgtup].append(po)
+        
+        for pkgs in pkgdict.values():
+            if len(pkgs) == 1:
+                continue
+                
+            pkgs.sort(_sort_by_cost)
+            lowcost = pkgs[0].repo.cost
+            #print '%s : %s : %s' % (pkgs[0], pkgs[0].repo, pkgs[0].repo.cost)
+            for pkg in pkgs[1:]:
+                if pkg.repo.cost > lowcost:
+                    pkg.repo.sack.delPackage(pkg)
+            
+        # for each pkg in all pkgs - if there are more than one matching a single
+        # nevra then sort by repo.cost and trim out the ones with the higher
+        # repo.cost
+        # if all the repo.costs are the same then leave them all alone
+        
+        pass
         
     def excludePackages(self, repo=None):
         """removes packages from packageSacks based on global exclude lists,
diff --git a/yum/config.py b/yum/config.py
index 293cb9d..a091c03 100644
--- a/yum/config.py
+++ b/yum/config.py
@@ -560,7 +560,8 @@ class RepoConf(BaseConfig):
     http_caching = Inherit(YumConf.http_caching)
     metadata_expire = Inherit(YumConf.metadata_expire)
     mirrorlist_expire = Inherit(YumConf.mirrorlist_expire)
-
+    cost = IntOption(1000)
+    
 def readStartupConfig(configfile, root):
     '''
     Parse Yum's main configuration file and return a StartupConf instance.
diff --git a/yum/packages.py b/yum/packages.py
index d11816e..bc4516c 100644
--- a/yum/packages.py
+++ b/yum/packages.py
@@ -747,6 +747,7 @@ class YumInstalledPackage(YumHeaderPackage):
     """super class for dealing with packages in the rpmdb"""
     def __init__(self, hdr):
         fakerepo = FakeRepository('installed')
+        fakerepo.cost = 0
         YumHeaderPackage.__init__(self, fakerepo, hdr)
 
 class YumLocalPackage(YumHeaderPackage):
@@ -774,6 +775,7 @@ class YumLocalPackage(YumHeaderPackage):
                 'Could not open local rpm file: %s' % self.localpath
         
         fakerepo = FakeRepository(filename)
+        fakerepo.cost = 0
         YumHeaderPackage.__init__(self, fakerepo, hdr)
         self.id = self.pkgid
         
diff --git a/yum/transactioninfo.py b/yum/transactioninfo.py
index 3ed67c5..e2dd550 100644
--- a/yum/transactioninfo.py
+++ b/yum/transactioninfo.py
@@ -174,6 +174,8 @@ class TransactionData:
                 condtxmbr = self.addInstall(po)
                 condtxmbr.setAsDep(po=txmember.po)
         
+        for oldpo in txmember.updates:
+            self.addUpdated(oldpo, txmember.po)
 
     def remove(self, pkgtup):
         """remove a package from the transaction"""
@@ -324,7 +326,7 @@ class TransactionData:
         if oldpo:
             txmbr.relatedto.append((oldpo.pkgtup, 'updates'))
             txmbr.updates.append(oldpo)
-            self.addUpdated(oldpo, po)
+            
         self.add(txmbr)
         return txmbr
 
diff --git a/yum/yumRepo.py b/yum/yumRepo.py
index e9f6e7f..c743220 100644
--- a/yum/yumRepo.py
+++ b/yum/yumRepo.py
@@ -233,6 +233,7 @@ class YumRepository(Repository, config.RepoConf):
         self.cachedir = ""
         self.pkgdir = ""
         self.hdrdir = ""
+        self.cost = 1000
         
         # holder for stuff we've grabbed
         self.retrieved = { 'primary':0, 'filelists':0, 'other':0, 'groups':0 }



More information about the Yum-cvs-commits mailing list