]> arthur.barton.de Git - bup.git/commitdiff
helpers: separately determine if stdout and stderr are ttys.
authorAvery Pennarun <apenwarr@gmail.com>
Sun, 20 Feb 2011 05:21:45 +0000 (21:21 -0800)
committerAvery Pennarun <apenwarr@gmail.com>
Sun, 20 Feb 2011 15:11:30 +0000 (07:11 -0800)
Previously we only cared if stderr was a tty (since we use that to determine
if we should print progress() or not).  But we might want to check stdout as
well, for the same reason that gzip does: we should be refusing to write
binary data to a terminal.

Signed-off-by: Avery Pennarun <apenwarr@gmail.com>
cmd/fsck-cmd.py
cmd/save-cmd.py
lib/bup/_helpers.c
lib/bup/helpers.py

index 44decd894e7983d4f20438ec59ecef61f0c4cb54..8ba2771d8ee7c3a3976393f8e80eca2f335d41e8 100755 (executable)
@@ -36,7 +36,7 @@ def par2_setup():
 
 def parv(lvl):
     if opt.verbose >= lvl:
-        if istty:
+        if istty2:
             return []
         else:
             return ['-q']
@@ -203,6 +203,6 @@ while len(outstanding):
     if not opt.verbose:
         progress('fsck (%d/%d)\r' % (count, len(extra)))
 
-if not opt.verbose and istty:
+if not opt.verbose and istty2:
     log('fsck done.           \n')
 sys.exit(code)
index 4b8ca121624f06bce7765a3d7eaa66a04e9ac76e..24376af0287149ae5ee3720bc4ed9b65f1ba4864 100755 (executable)
@@ -31,7 +31,7 @@ if not (opt.tree or opt.commit or opt.name):
 if not extra:
     o.fatal("no filenames given")
 
-opt.progress = (istty and not opt.quiet)
+opt.progress = (istty2 and not opt.quiet)
 opt.smaller = parse_num(opt.smaller or 0)
 if opt.bwlimit:
     client.bwlimit = parse_num(opt.bwlimit)
index d077cd9710c08bd007f1a8424cd4ea2f326333ff..af9d06f35273cabe4304d1142eb62d7b6e24cee8 100644 (file)
@@ -9,7 +9,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 
-static int istty = 0;
+static int istty2 = 0;
 
 // Probably we should use autoconf or something and set HAVE_PY_GETARGCARGV...
 #if __WIN32__ || __CYGWIN__
@@ -400,7 +400,7 @@ static PyObject *merge_into(PyObject *self, PyObject *args)
     {
        struct idx *idx;
        uint32_t new_prefix;
-       if (count % 102424 == 0 && istty)
+       if (count % 102424 == 0 && istty2)
            fprintf(stderr, "midx: writing %.2f%% (%d/%d)\r",
                    count*100.0/total, count, total);
        idx = idxs[last_i];
@@ -655,7 +655,8 @@ static PyMethodDef faster_methods[] = {
 
 PyMODINIT_FUNC init_helpers(void)
 {
+    char *e = getenv("BUP_FORCE_TTY");
     Py_InitModule("_helpers", faster_methods);
-    istty = isatty(2) || getenv("BUP_FORCE_TTY");
+    istty2 = isatty(2) || (atoi(e ? e : "0") & 2);
     unpythonize_argv();
 }
index ed976bfe3aba41dab44a97537f0555d492560747..1432b8b19273297867da7f9224f8e682fb95c6a4 100644 (file)
@@ -66,12 +66,13 @@ 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."""
     global _last_progress
-    if istty:
+    if istty2:
         log(s)
         _last_progress = s