From 9ebba5607f2e09c96eb88248499973ca3f3e1005 Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Sun, 19 Jun 2016 14:50:21 -0400 Subject: Flush stdout to interleave properly with subprocesses. --- repo-foreach.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/repo-foreach.py b/repo-foreach.py index ea18a39..85a2888 100755 --- a/repo-foreach.py +++ b/repo-foreach.py @@ -5,7 +5,7 @@ from subprocess import call from os import walk from argparse import ArgumentParser -from sys import exit +from sys import exit, stdout parser = ArgumentParser() parser.add_argument("-t", "--tree", default = ".", help = "repository tree to walk") @@ -13,12 +13,17 @@ parser.add_argument("-v", "--verbose", action = "store_true", help = "whistle wh parser.add_argument("command", nargs = "+", help = "command to run in each repository") args = parser.parse_args() +def log(msg): + if args.verbose: + stdout.write(msg) + stdout.write("\n") + stdout.flush() + status = 0 for head, dirs, files in walk(args.tree): if ".git" in dirs and not head.endswith("/gitolite"): - if args.verbose: - print head + log(head) status |= call(args.command, cwd = head) exit(status) -- cgit v1.2.3