[yum-cvs] yum/yum mdcache.py, 1.4, 1.5 repos.py, 1.67, 1.68 sqlitecache.py, 1.6, 1.7

Menno Smits mjs at login.linux.duke.edu
Wed Mar 2 22:18:46 UTC 2005


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

Modified Files:
	mdcache.py repos.py sqlitecache.py 
Log Message:
Enhanced callback for reporting cache update progress (no more prints in sqlite code).


Index: mdcache.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/mdcache.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- mdcache.py	15 Oct 2004 06:48:16 -0000	1.4
+++ mdcache.py	2 Mar 2005 22:18:43 -0000	1.5
@@ -143,7 +143,8 @@
                     if pkgid:
                         obj = OtherEntry(reader)
                         databank[pkgid] = obj
-                if self.callback is not None: self.callback(count, total, 'MD Read')
+                if self.callback: 
+                    self.callback.progressbar(count, total, 'MD Read')
         self.debugprint('Parsed %s packages' % count)
         reader.Close()
         del reader

Index: repos.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/repos.py,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -r1.67 -r1.68
--- repos.py	2 Mar 2005 20:07:37 -0000	1.67
+++ repos.py	2 Mar 2005 22:18:43 -0000	1.68
@@ -49,7 +49,7 @@
             current = 0        
             for pkgid in dataobj.keys():
                 current += 1
-                if callback: callback(current, total, repoid)
+                if callback: callback.progressbar(current, total, repoid)
                 pkgdict = dataobj[pkgid]
                 po = self.pc(pkgdict, repoid)
                 po.simple['id'] = pkgid
@@ -70,7 +70,7 @@
             current = 0
             for pkgid in dataobj.keys():
                 current += 1
-                if callback: callback(current, total, repoid)
+                if callback: callback.progressbar(current, total, repoid)
                 pkgdict = dataobj[pkgid]
                 if self.pkgsByID.has_key(pkgid):
                     for po in self.pkgsByID[pkgid]:
@@ -212,9 +212,16 @@
         for repo in myrepos:
             if not hasattr(repo, 'cacheHandler'):
                 if (self.sqlite):
-                    repo.cacheHandler = self.sqlitecache.RepodataParserSqlite(storedir=repo.cachedir, repoid=repo.id, callback=callback)
+                    repo.cacheHandler = self.sqlitecache.RepodataParserSqlite(
+                            storedir=repo.cachedir, 
+                            repoid=repo.id,
+                            callback=callback,
+                            )
                 else:
-                    repo.cacheHandler = mdcache.RepodataParser(storedir=repo.cachedir, callback=callback)
+                    repo.cacheHandler = mdcache.RepodataParser(
+                            storedir=repo.cachedir, 
+                            callback=callback
+                            )
             for item in data:
                 if self.pkgSack.added.has_key(repo.id):
                     if item in self.pkgSack.added[repo.id]:

Index: sqlitecache.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/sqlitecache.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- sqlitecache.py	2 Mar 2005 20:07:37 -0000	1.6
+++ sqlitecache.py	2 Mar 2005 22:18:43 -0000	1.7
@@ -15,11 +15,9 @@
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 # Copyright 2005 Duke University 
 
-#
 # TODO
 # - Add support for multiple checksums per rpm (is this required??)
 # - Store filetypes as one char per type instead of a string
-# - don't use print for output, use yum's output functions instead
 # - Move the stuff that turns a list of files into a string into a helper unit
 # - Don't fall back to a memory sqlite cache but to pickles if a cache
 #   file can't be created.
@@ -61,8 +59,10 @@
 
         # Now check the database version
         if (info['dbversion'] != dbversion):
-            print "Warning your cache file is version %s, we need %s" % (info['dbversion'],dbversion)
+            self.log(2, "Warning: cache file is version %s, we need %s, will regenerate" % (
+                info['dbversion'], dbversion))
             raise sqlite.DatabaseError, "Older version of yum sqlite"
+
         # This appears to be a valid database, return checksum value and 
         # database object
         return (info['checksum'],db)
@@ -87,9 +87,7 @@
         # db should now contain a valid database object, check if it is
         # up to date
         if (checksum != dbchecksum):
-
-            print "%s sqlite cache needs updating, reading in metadata" % (
-                    metadatatype)
+            self.log(3, "%s sqlite cache needs updating, reading in metadata" % (metadatatype))
             parser = mdparser.MDParser(location)
             self.updateSqliteCache(db, parser, checksum, metadatatype)
         db.commit()
@@ -221,7 +219,7 @@
 
         # If it exists, remove it as we were asked to create a new one
         if (os.path.exists(filename)):
-            print "Warning file already exists, removing old version"
+            self.log(3, "Warning: cache already exists, removing old version")
             os.unlink(filename)
 
         # Try to create the databse in filename, or use in memory when
@@ -230,7 +228,7 @@
             f = open(filename,'w')
             db = sqlite.connect(filename) 
         except IOError:
-            print "Warning could not create sqlite cache file, using in memory cache instead"
+            self.log(1, "Warning could not create sqlite cache file, using in memory cache instead")
             db = sqlite.connect(":memory:")
 
         # The file has been created, now create the tables and indexes
@@ -343,7 +341,7 @@
         for package in parser:
 
             if self.callback is not None:
-                self.callback(parser.count, parser.total, self.repoid)
+                self.callback.progressbar(parser.count, parser.total, self.repoid)
 
             pkgId = package['pkgId']
             all_pkgIds[pkgId] = 1
@@ -374,10 +372,15 @@
         cur.execute("INSERT into db_info (dbversion,checksum) VALUES (%s,%s)",
                 (dbversion,checksum))
         db.commit()
-        print "Added %s new packages, deleted %s old in %.2f seconds" % (
-                newcount, delcount, time.time()-t)
+        self.log(2, "Added %s new packages, deleted %s old in %.2f seconds" % (
+                newcount, delcount, time.time()-t))
         return db
 
+    def log(self, level, msg):
+        '''Log to callback (if set)
+        '''
+        if self.callback:
+            self.callback.log(level, msg)
 
 class PackageToDBAdapter:
 




More information about the Yum-cvs-commits mailing list