]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/helpers.py
Merge branch 'master' into meta
[bup.git] / lib / bup / helpers.py
index 0cbb1ebc8bff0397a5114e58d7af2cbfaddb15f5..13125afbfa8d373c7bf29f4ca88a29f4e8d372a5 100644 (file)
@@ -67,17 +67,22 @@ def debug2(s):
         log(s)
 
 
-istty = os.isatty(2) or atoi(os.environ.get('BUP_FORCE_TTY'))
+istty1 = os.isatty(1) or (atoi(os.environ.get('BUP_FORCE_TTY')) & 1)
+istty2 = os.isatty(2) or (atoi(os.environ.get('BUP_FORCE_TTY')) & 2)
+_last_progress = ''
 def progress(s):
     """Calls log() if stderr is a TTY.  Does nothing otherwise."""
-    if istty:
+    global _last_progress
+    if istty2:
         log(s)
+        _last_progress = 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."""
+    This avoids overloading the stderr buffer with excess junk.
+    """
     global _last_prog
     now = time.time()
     if now - _last_prog > 0.1:
@@ -85,6 +90,16 @@ def qprogress(s):
         _last_prog = now
 
 
+def reprogress():
+    """Calls progress() to redisplay the most recent progress message.
+
+    Useful after you've printed some other message that wipes out the
+    progress line.
+    """
+    if _last_progress and _last_progress.endswith('\r'):
+        progress(_last_progress)
+
+
 def mkdirp(d, mode=None):
     """Recursively create directories on path 'd'.