]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/helpers.py
Merge remote branch 'origin/master' into meta
[bup.git] / lib / bup / helpers.py
index 566343d2b0e4518b90e1ccacb9c656d4688c070a..0cbb1ebc8bff0397a5114e58d7af2cbfaddb15f5 100644 (file)
@@ -1,8 +1,8 @@
 """Helper functions and classes for bup."""
 
 import sys, os, pwd, subprocess, errno, socket, select, mmap, stat, re, struct
-import heapq, operator
-from bup import _version
+import heapq, operator, time
+from bup import _version, _helpers
 import bup._helpers as _helpers
 
 # This function should really be in helpers, not in bup.options.  But we
@@ -47,10 +47,14 @@ def _hard_write(fd, buf):
         assert(sz >= 0)
         buf = buf[sz:]
 
+
+_last_prog = 0
 def log(s):
     """Print a log message to stderr."""
+    global _last_prog
     sys.stdout.flush()
     _hard_write(sys.stderr.fileno(), s)
+    _last_prog = 0
 
 
 def debug1(s):
@@ -63,6 +67,24 @@ def debug2(s):
         log(s)
 
 
+istty = os.isatty(2) or atoi(os.environ.get('BUP_FORCE_TTY'))
+def progress(s):
+    """Calls log() if stderr is a TTY.  Does nothing otherwise."""
+    if istty:
+        log(s)
+
+
+def qprogress(s):
+    """Calls progress() only if we haven't printed progress in a while.
+    
+    This avoids overloading the stderr buffer with excess junk."""
+    global _last_prog
+    now = time.time()
+    if now - _last_prog > 0.1:
+        progress(s)
+        _last_prog = now
+
+
 def mkdirp(d, mode=None):
     """Recursively create directories on path 'd'.
 
@@ -546,13 +568,6 @@ def clear_errors():
     saved_errors = []
 
 
-istty = os.isatty(2) or atoi(os.environ.get('BUP_FORCE_TTY'))
-def progress(s):
-    """Calls log(s) if stderr is a TTY.  Does nothing otherwise."""
-    if istty:
-        log(s)
-
-
 def handle_ctrl_c():
     """Replace the default exception handler for KeyboardInterrupt (Ctrl-C).