From: Avery Pennarun Date: Thu, 17 Feb 2011 00:11:26 +0000 (-0800) Subject: Use the new qprogress() function in more places. X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=c562914b5d2027309ab007162da52e0e8438296a;p=packages%2Fb%2Fbup.git Use the new qprogress() function in more places. 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 --- diff --git a/cmd/index-cmd.py b/cmd/index-cmd.py index b3abb90..a043550 100755 --- a/cmd/index-cmd.py +++ b/cmd/index-cmd.py @@ -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(): diff --git a/cmd/restore-cmd.py b/cmd/restore-cmd.py index 6ebebec..445d9d0 100755 --- a/cmd/restore-cmd.py +++ b/cmd/restore-cmd.py @@ -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)) diff --git a/cmd/save-cmd.py b/cmd/save-cmd.py index ffbe94b..8c2ba40 100755 --- a/cmd/save-cmd.py +++ b/cmd/save-cmd.py @@ -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: diff --git a/cmd/split-cmd.py b/cmd/split-cmd.py index 1673b2b..756d1b5 100755 --- a/cmd/split-cmd.py +++ b/cmd/split-cmd.py @@ -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') diff --git a/lib/bup/client.py b/lib/bup/client.py index 8d2fbb9..f83859f 100644 --- a/lib/bup/client.py +++ b/lib/bup/client.py @@ -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() diff --git a/lib/bup/git.py b/lib/bup/git.py index 659164f..f0fa0dd 100644 --- a/lib/bup/git.py +++ b/lib/bup/git.py @@ -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) diff --git a/lib/bup/index.py b/lib/bup/index.py index 72a7296..f35fdc8 100644 --- a/lib/bup/index.py +++ b/lib/bup/index.py @@ -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')