[yum-cvs] yum cli.py,1.160,1.161 output.py,1.48,1.49

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


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

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


Index: cli.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/cli.py,v
retrieving revision 1.160
retrieving revision 1.161
diff -u -r1.160 -r1.161
--- cli.py	2 Mar 2005 07:27:59 -0000	1.160
+++ cli.py	2 Mar 2005 22:18:43 -0000	1.161
@@ -259,7 +259,8 @@
             self.repos.callback = None
         else:
             self.repos.setProgressBar(TextMeter(fo=sys.stdout))
-            self.repos.callback = self.simpleProgressBar
+            self.repos.callback = output.CacheProgressCallback(self.log,
+                    self.errorlog, self.filelog)
 
         # setup our failure report for failover
         freport = (self.failureReport,(),{})

Index: output.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/output.py,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -r1.48 -r1.49
--- output.py	2 Mar 2005 12:03:13 -0000	1.48
+++ output.py	2 Mar 2005 22:18:43 -0000	1.49
@@ -46,35 +46,7 @@
     
         
     def simpleProgressBar(self, current, total, name=None):
-        """simple progress bar 50 # marks"""
-        
-        mark = '#'
-        if not sys.stdout.isatty():
-            return
-            
-        if current == 0:
-            percent = 0 
-        else:
-            if total != 0:
-                percent = current*100/total
-            else:
-                percent = 0
-    
-        numblocks = int(percent/2)
-        hashbar = mark * numblocks
-        if name is None:
-            output = '\r%-50s %d/%d' % (hashbar, current, total)
-        else:
-            output = '\r%-10.10s: %-50s %d/%d' % (name, hashbar, current, total)
-         
-        if current <= total:
-            sys.stdout.write(output)
-    
-        if current == total:
-            sys.stdout.write('\n')
-    
-        sys.stdout.flush()
-        
+        progressbar(current, total, name)
     
     def simpleList(self, pkg):
         ver = pkg.printVer()
@@ -509,4 +481,61 @@
     
     def downloadHeader(self, name):
         self.log(2, '---> Downloading header for %s to pack into transaction set.' % name)
+       
+
+class CacheProgressCallback:
+
+    '''
+    The class handles text output callbacks during metadata cache updates.
+    '''
+    
+    def __init__(self, log, errorlog, filelog=None):
+        self.log = log
+        self.errorlog = errorlog
+        self.filelog = filelog
+
+    def log(self, level, message):
+        self.log(level, message)
+
+    def errorlog(self, level, message):
+        if self.errorlog:
+            self.errorlog(level, message)
+
+    def filelog(self, level, message):
+        if self.filelog:
+            self.filelog(level, message)
+
+    def progressbar(self, current, total, name=None):
+        progressbar(current, total, name)
+
+
+def progressbar(current, total, name=None):
+    """simple progress bar 50 # marks"""
+    
+    mark = '#'
+    if not sys.stdout.isatty():
+        return
+        
+    if current == 0:
+        percent = 0 
+    else:
+        if total != 0:
+            percent = current*100/total
+        else:
+            percent = 0
+
+    numblocks = int(percent/2)
+    hashbar = mark * numblocks
+    if name is None:
+        output = '\r%-50s %d/%d' % (hashbar, current, total)
+    else:
+        output = '\r%-10.10s: %-50s %d/%d' % (name, hashbar, current, total)
+     
+    if current <= total:
+        sys.stdout.write(output)
+
+    if current == total:
+        sys.stdout.write('\n')
+
+    sys.stdout.flush()
         




More information about the Yum-cvs-commits mailing list