]> arthur.barton.de Git - bup.git/commitdiff
Use the new qprogress() function in more places.
authorAvery Pennarun <apenwarr@gmail.com>
Thu, 17 Feb 2011 00:11:26 +0000 (16:11 -0800)
committerAvery Pennarun <apenwarr@gmail.com>
Thu, 17 Feb 2011 02:21:44 +0000 (18:21 -0800)
qprogress() was introduced in the last commit and has smarter default
behaviour that automatically reduces progress output so we don't print too
many messages per second.  Various commands/etc were doing this in various
different ad-hoc ways, but let's centralize it all in one place.

Signed-off-by: Avery Pennarun <apenwarr@gmail.com>
cmd/index-cmd.py
cmd/restore-cmd.py
cmd/save-cmd.py
cmd/split-cmd.py
lib/bup/client.py
lib/bup/git.py
lib/bup/index.py

index b3abb902e31bc2ccc2e9666b7a7be06b99b927a2..a04355096406c837ef29911387aceb3597f04a03 100755 (executable)
@@ -67,9 +67,9 @@ def update_index(top, excluded_paths):
         if opt.verbose>=2 or (opt.verbose==1 and stat.S_ISDIR(pst.st_mode)):
             sys.stdout.write('%s\n' % path)
             sys.stdout.flush()
-            progress('Indexing: %d\r' % total)
+            qprogress('Indexing: %d\r' % total)
         elif not (total % 128):
-            progress('Indexing: %d\r' % total)
+            qprogress('Indexing: %d\r' % total)
         total += 1
         while rig.cur and rig.cur.name > path:  # deleted paths
             if rig.cur.exists():
index 6ebebec9fc405874c5f9d5440b438bf665df0f77..445d9d05ccfc1da9a255a163f1b45e367d203ce8 100755 (executable)
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-import sys, stat, time
+import sys, stat
 from bup import options, git, vfs
 from bup.helpers import *
 
@@ -11,31 +11,23 @@ v,verbose  increase log output (can be used more than once)
 q,quiet    don't show progress meter
 """
 
-total_restored = last_progress = 0
+total_restored = 0
 
 
 def verbose1(s):
-    global last_progress
     if opt.verbose >= 1:
         print s
-        last_progress = 0
 
 
 def verbose2(s):
-    global last_progress
     if opt.verbose >= 2:
         print s
-        last_progress = 0
 
 
 def plog(s):
-    global last_progress
     if opt.quiet:
         return
-    now = time.time()
-    if now - last_progress > 0.2:
-        progress(s)
-        last_progress = now
+    qprogress(s)
 
 
 def do_node(top, n):
@@ -98,7 +90,7 @@ for d in extra:
         do_node(n.parent, n)
 
 if not opt.quiet:
-    log('Restoring: %d, done.\n' % total_restored)
+    progress('Restoring: %d, done.\n' % total_restored)
 
 if saved_errors:
     log('WARNING: %d errors encountered while restoring.\n' % len(saved_errors))
index ffbe94be041432ab848c864f1d3da709cb1e2068..8c2ba40abe61382ea5a46ebf99f9fee007432842 100755 (executable)
@@ -107,9 +107,8 @@ def _pop(force_tree):
     return tree
 
 lastremain = None
-lastprint = 0
 def progress_report(n):
-    global count, subcount, lastremain, lastprint
+    global count, subcount, lastremain
     subcount += n
     cc = count + subcount
     pct = total and (cc*100.0/total) or 0
@@ -141,17 +140,9 @@ def progress_report(n):
             remainstr = '%dm%d' % (mins, secs)
         else:
             remainstr = '%ds' % secs
-    if now - lastprint > 0.1:
-        progress('Saving: %.2f%% (%d/%dk, %d/%d files) %s %s\r'
-                 % (pct, cc/1024, total/1024, fcount, ftotal,
-                    remainstr, kpsstr))
-        lastprint = now
-
-
-def vlog(s):
-    global lastprint
-    lastprint = 0
-    log(s)
+    qprogress('Saving: %.2f%% (%d/%dk, %d/%d files) %s %s\r'
+              % (pct, cc/1024, total/1024, fcount, ftotal,
+                 remainstr, kpsstr))
 
 
 indexfile = opt.indexfile or git.repo('bupindex')
@@ -170,7 +161,7 @@ total = ftotal = 0
 if opt.progress:
     for (transname,ent) in r.filter(extra, wantrecurse=wantrecurse_pre):
         if not (ftotal % 10024):
-            progress('Reading index: %d\r' % ftotal)
+            qprogress('Reading index: %d\r' % ftotal)
         exists = ent.exists()
         hashvalid = already_saved(ent)
         ent.set_sha_missing(not hashvalid)
@@ -202,10 +193,10 @@ for (transname,ent) in r.filter(extra, wantrecurse=wantrecurse_during):
         else:
             status = ' '
         if opt.verbose >= 2:
-            vlog('%s %-70s\n' % (status, ent.name))
+            log('%s %-70s\n' % (status, ent.name))
         elif not stat.S_ISDIR(ent.mode) and lastdir != dir:
             if not lastdir.startswith(dir):
-                vlog('%s %-70s\n' % (status, os.path.join(dir, '')))
+                log('%s %-70s\n' % (status, os.path.join(dir, '')))
             lastdir = dir
 
     if opt.progress:
index 1673b2b1dcee765c976649e4a4933be58b4894da..756d1b566a3937c7db7e3b62d48b98529b18579a 100755 (executable)
@@ -58,19 +58,15 @@ else:
     date = time.time()
 
 
-last_prog = total_bytes = 0
+total_bytes = 0
 def prog(filenum, nbytes):
-    global last_prog, total_bytes
+    global total_bytes
     total_bytes += nbytes
-    now = time.time()
-    if now - last_prog < 0.2:
-        return
     if filenum > 0:
-        progress('Splitting: file #%d, %d kbytes\r'
-                 % (filenum+1, total_bytes/1024))
+        qprogress('Splitting: file #%d, %d kbytes\r'
+                  % (filenum+1, total_bytes/1024))
     else:
-        progress('Splitting: %d kbytes\r' % (total_bytes/1024))
-    last_prog = now
+        qprogress('Splitting: %d kbytes\r' % (total_bytes/1024))
 
 
 is_reverse = os.environ.get('BUP_SERVER_REVERSE')
index 8d2fbb99fef23c4755ac8c32ed5542993f1400fa..f83859fccbc0ec996015c3b0d397d97c34bff12a 100644 (file)
@@ -192,7 +192,7 @@ class Client:
         for b in chunkyreader(self.conn, n):
             f.write(b)
             count += len(b)
-            progress('Receiving index from server: %d/%d\r' % (count, n))
+            qprogress('Receiving index from server: %d/%d\r' % (count, n))
         progress('Receiving index from server: %d/%d, done.\n' % (count, n))
         self.check_ok()
         f.close()
index 659164fc4ea859131c662ae2739643935afc5f17..f0fa0dd871b793ae17b9318e08a39a52bb8e0960 100644 (file)
@@ -767,11 +767,12 @@ def open_idx(filename):
 def idxmerge(idxlist, final_progress=True):
     """Generate a list of all the objects reachable in a PackIdxList."""
     def pfunc(count, total):
-        progress('Reading indexes: %.2f%% (%d/%d)\r'
-                 % (count*100.0/total, count, total))
+        qprogress('Reading indexes: %.2f%% (%d/%d)\r'
+                  % (count*100.0/total, count, total))
     def pfinal(count, total):
         if final_progress:
-            log('Reading indexes: %.2f%% (%d/%d), done.\n' % (100, total, total))
+            progress('Reading indexes: %.2f%% (%d/%d), done.\n'
+                     % (100, total, total))
     return merge_iter(idxlist, 10024, pfunc, pfinal)
 
 
index 72a7296ea4fda43e299662873fbc77aa8947ff89..f35fdc87db14c89a118892a05cc898e5e9079402 100644 (file)
@@ -454,7 +454,7 @@ def reduce_paths(paths):
 
 def merge(*iters):
     def pfunc(count, total):
-        progress('bup: merging indexes (%d/%d)\r' % (count, total))
+        qprogress('bup: merging indexes (%d/%d)\r' % (count, total))
     def pfinal(count, total):
-        log('bup: merging indexes (%d/%d), done.\n' % (count, total))
+        progress('bup: merging indexes (%d/%d), done.\n' % (count, total))
     return merge_iter(iters, 1024, pfunc, pfinal, key='name')