Show More
@@ -8,6 +8,7 b'' | |||||
8 | from i18n import _ |
|
8 | from i18n import _ | |
9 | import encoding |
|
9 | import encoding | |
10 | import os, sys, errno, stat, getpass, pwd, grp, socket, tempfile, unicodedata |
|
10 | import os, sys, errno, stat, getpass, pwd, grp, socket, tempfile, unicodedata | |
|
11 | import fcntl | |||
11 |
|
12 | |||
12 | posixfile = open |
|
13 | posixfile = open | |
13 | normpath = os.path.normpath |
|
14 | normpath = os.path.normpath | |
@@ -432,7 +433,7 b' def gethgcmd():' | |||||
432 |
|
433 | |||
433 | def termwidth(): |
|
434 | def termwidth(): | |
434 | try: |
|
435 | try: | |
435 |
import termios, array |
|
436 | import termios, array | |
436 | for dev in (sys.stderr, sys.stdout, sys.stdin): |
|
437 | for dev in (sys.stderr, sys.stdout, sys.stdin): | |
437 | try: |
|
438 | try: | |
438 | try: |
|
439 | try: | |
@@ -570,13 +571,24 b' def statisexec(st):' | |||||
570 |
|
571 | |||
571 | def readpipe(pipe): |
|
572 | def readpipe(pipe): | |
572 | """Read all available data from a pipe.""" |
|
573 | """Read all available data from a pipe.""" | |
573 | chunks = [] |
|
574 | # We can't fstat() a pipe because Linux will always report 0. | |
574 | while True: |
|
575 | # So, we set the pipe to non-blocking mode and read everything | |
575 | size = os.fstat(pipe.fileno()).st_size |
|
576 | # that's available. | |
576 | if not size: |
|
577 | flags = fcntl.fcntl(pipe, fcntl.F_GETFL) | |
577 | break |
|
578 | flags |= os.O_NONBLOCK | |
|
579 | oldflags = fcntl.fcntl(pipe, fcntl.F_SETFL, flags) | |||
578 |
|
580 | |||
579 | s = pipe.read(size) |
|
581 | try: | |
580 | if not s: |
|
582 | chunks = [] | |
581 |
|
|
583 | while True: | |
582 | chunks.append(s) |
|
584 | try: | |
|
585 | s = pipe.read() | |||
|
586 | if not s: | |||
|
587 | break | |||
|
588 | chunks.append(s) | |||
|
589 | except IOError: | |||
|
590 | break | |||
|
591 | ||||
|
592 | return ''.join(chunks) | |||
|
593 | finally: | |||
|
594 | fcntl.fcntl(pipe, fcntl.F_SETFL, oldflags) |
General Comments 0
You need to be logged in to leave comments.
Login now