]> git.michaelhowe.org Git - packages/b/bup.git/commitdiff
midx4: Properly decide whether to do progress in C
authorBrandon Low <lostlogic@lostlogicx.com>
Tue, 8 Feb 2011 02:30:04 +0000 (18:30 -0800)
committerAvery Pennarun <apenwarr@gmail.com>
Tue, 8 Feb 2011 03:01:31 +0000 (19:01 -0800)
Basically just gives us a _helpers.istty to go along with helpers.istty
and uses it to decide whether or not to write progress messages from
midx4 generation.

Signed-off-by: Brandon Low <lostlogic@lostlogicx.com>
lib/bup/_helpers.c

index d6e5898ef7a1658927476eed91815708bccb2463..938b7a3ad50ffbec02cc8193608779d62dde7854 100644 (file)
@@ -4,6 +4,11 @@
 #include <stdint.h>
 #include <fcntl.h>
 #include <arpa/inet.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+static int istty = 0;
 
 static PyObject *selftest(PyObject *self, PyObject *args)
 {
@@ -338,8 +343,8 @@ static PyObject *merge_into(PyObject *self, PyObject *args)
     {
        struct idx *idx;
        uint32_t new_prefix;
-       if (count % 102424 == 0)
-           PySys_WriteStderr("midx: writing %.2f%% (%d/%d)\r",
+       if (count % 102424 == 0 && istty)
+           fprintf(stderr, "midx: writing %.2f%% (%d/%d)\r",
                    count*100.0/total, count, total);
        idx = idxs[last_i];
        new_prefix = _extract_bits((unsigned char *)idx->cur, bits);
@@ -517,4 +522,5 @@ static PyMethodDef faster_methods[] = {
 PyMODINIT_FUNC init_helpers(void)
 {
     Py_InitModule("_helpers", faster_methods);
+    istty = isatty(2) || getenv("BUP_FORCE_TTY");
 }