mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
sync: Handle case when output isn't connected to a terminal
Currently `repo sync | tee` exits with an OSError. Bug: https://crbug.com/gerrit/17023 Change-Id: I91ae05f1c91d374b5d57721d45af74db1b2072a5 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/376414 Tested-by: Gavin Mak <gavinmak@google.com> Reviewed-by: Mike Frysinger <vapier@google.com> Commit-Queue: Gavin Mak <gavinmak@google.com>
This commit is contained in:
parent
945c006f40
commit
b2263ba124
11
progress.py
11
progress.py
@ -23,7 +23,7 @@ except ImportError:
|
||||
|
||||
from repo_trace import IsTraceToStderr
|
||||
|
||||
_NOT_TTY = not os.isatty(2)
|
||||
_TTY = sys.stderr.isatty()
|
||||
|
||||
# This will erase all content in the current line (wherever the cursor is).
|
||||
# It does not move the cursor, so this is usually followed by \r to move to
|
||||
@ -97,7 +97,8 @@ class Progress(object):
|
||||
self._start = time.time()
|
||||
self._show = not delay
|
||||
self._units = units
|
||||
self._elide = elide
|
||||
self._elide = elide and _TTY
|
||||
|
||||
# Only show the active jobs section if we run more than one in parallel.
|
||||
self._show_jobs = False
|
||||
self._active = 0
|
||||
@ -129,7 +130,7 @@ class Progress(object):
|
||||
def _write(self, s):
|
||||
s = "\r" + s
|
||||
if self._elide:
|
||||
col = os.get_terminal_size().columns
|
||||
col = os.get_terminal_size(sys.stderr.fileno()).columns
|
||||
if len(s) > col:
|
||||
s = s[: col - 1] + ".."
|
||||
sys.stderr.write(s)
|
||||
@ -157,7 +158,7 @@ class Progress(object):
|
||||
msg = self._last_msg
|
||||
self._last_msg = msg
|
||||
|
||||
if _NOT_TTY or IsTraceToStderr():
|
||||
if not _TTY or IsTraceToStderr():
|
||||
return
|
||||
|
||||
elapsed_sec = time.time() - self._start
|
||||
@ -199,7 +200,7 @@ class Progress(object):
|
||||
|
||||
def end(self):
|
||||
self._update_event.set()
|
||||
if _NOT_TTY or IsTraceToStderr() or not self._show:
|
||||
if not _TTY or IsTraceToStderr() or not self._show:
|
||||
return
|
||||
|
||||
duration = duration_str(time.time() - self._start)
|
||||
|
Loading…
Reference in New Issue
Block a user