diff options
author | Rob Austein <sra@hactrn.net> | 2016-06-19 14:50:21 -0400 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2016-06-19 14:50:21 -0400 |
commit | 9ebba5607f2e09c96eb88248499973ca3f3e1005 (patch) | |
tree | d5c2088f26f3b593c7ccb8695adf786c6559b25d | |
parent | a07d639bf75fbe392a96ad91ffaeb0dbb63b865d (diff) |
Flush stdout to interleave properly with subprocesses.
-rwxr-xr-x | repo-foreach.py | 11 |
1 files 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) |