diff options
Diffstat (limited to 'subcmds/forall.py')
-rw-r--r-- | subcmds/forall.py | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/subcmds/forall.py b/subcmds/forall.py index 07ee8d58..52eb5e28 100644 --- a/subcmds/forall.py +++ b/subcmds/forall.py | |||
@@ -15,17 +15,16 @@ | |||
15 | 15 | ||
16 | from __future__ import print_function | 16 | from __future__ import print_function |
17 | import errno | 17 | import errno |
18 | import fcntl | ||
19 | import multiprocessing | 18 | import multiprocessing |
20 | import re | 19 | import re |
21 | import os | 20 | import os |
22 | import select | ||
23 | import signal | 21 | import signal |
24 | import sys | 22 | import sys |
25 | import subprocess | 23 | import subprocess |
26 | 24 | ||
27 | from color import Coloring | 25 | from color import Coloring |
28 | from command import Command, MirrorSafeCommand | 26 | from command import Command, MirrorSafeCommand |
27 | import platform_utils | ||
29 | 28 | ||
30 | _CAN_COLOR = [ | 29 | _CAN_COLOR = [ |
31 | 'branch', | 30 | 'branch', |
@@ -105,6 +104,13 @@ annotating tree details. | |||
105 | shell positional arguments ($1, $2, .., $#) are set to any arguments | 104 | shell positional arguments ($1, $2, .., $#) are set to any arguments |
106 | following <command>. | 105 | following <command>. |
107 | 106 | ||
107 | Example: to list projects: | ||
108 | |||
109 | %prog% forall -c 'echo $REPO_PROJECT' | ||
110 | |||
111 | Notice that $REPO_PROJECT is quoted to ensure it is expanded in | ||
112 | the context of running <command> instead of in the calling shell. | ||
113 | |||
108 | Unless -p is used, stdin, stdout, stderr are inherited from the | 114 | Unless -p is used, stdin, stdout, stderr are inherited from the |
109 | terminal and are not redirected. | 115 | terminal and are not redirected. |
110 | 116 | ||
@@ -344,35 +350,25 @@ def DoWork(project, mirror, opt, cmd, shell, cnt, config): | |||
344 | if opt.project_header: | 350 | if opt.project_header: |
345 | out = ForallColoring(config) | 351 | out = ForallColoring(config) |
346 | out.redirect(sys.stdout) | 352 | out.redirect(sys.stdout) |
347 | class sfd(object): | ||
348 | def __init__(self, fd, dest): | ||
349 | self.fd = fd | ||
350 | self.dest = dest | ||
351 | def fileno(self): | ||
352 | return self.fd.fileno() | ||
353 | |||
354 | empty = True | 353 | empty = True |
355 | errbuf = '' | 354 | errbuf = '' |
356 | 355 | ||
357 | p.stdin.close() | 356 | p.stdin.close() |
358 | s_in = [sfd(p.stdout, sys.stdout), | 357 | s_in = platform_utils.FileDescriptorStreams.create() |
359 | sfd(p.stderr, sys.stderr)] | 358 | s_in.add(p.stdout, sys.stdout, 'stdout') |
360 | 359 | s_in.add(p.stderr, sys.stderr, 'stderr') | |
361 | for s in s_in: | ||
362 | flags = fcntl.fcntl(s.fd, fcntl.F_GETFL) | ||
363 | fcntl.fcntl(s.fd, fcntl.F_SETFL, flags | os.O_NONBLOCK) | ||
364 | 360 | ||
365 | while s_in: | 361 | while not s_in.is_done: |
366 | in_ready, _out_ready, _err_ready = select.select(s_in, [], []) | 362 | in_ready = s_in.select() |
367 | for s in in_ready: | 363 | for s in in_ready: |
368 | buf = s.fd.read(4096) | 364 | buf = s.read() |
369 | if not buf: | 365 | if not buf: |
370 | s.fd.close() | 366 | s.close() |
371 | s_in.remove(s) | 367 | s_in.remove(s) |
372 | continue | 368 | continue |
373 | 369 | ||
374 | if not opt.verbose: | 370 | if not opt.verbose: |
375 | if s.fd != p.stdout: | 371 | if s.std_name == 'stderr': |
376 | errbuf += buf | 372 | errbuf += buf |
377 | continue | 373 | continue |
378 | 374 | ||