summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGavin Mak <gavinmak@google.com>2023-06-07 21:59:17 +0000
committerLUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-06-09 15:26:16 +0000
commitb2263ba1245f12428a63e19ced88f27d92d7ca7a (patch)
tree1d14f0bf79a6f9b0b6ef507619177945cbb19c3a
parent945c006f406550add8a3cad32ada0791f5a15c53 (diff)
downloadgit-repo-b2263ba1245f12428a63e19ced88f27d92d7ca7a.tar.gz
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>
-rw-r--r--progress.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/progress.py b/progress.py
index 69c95927..f2edf144 100644
--- a/progress.py
+++ b/progress.py
@@ -23,7 +23,7 @@ except ImportError:
23 23
24from repo_trace import IsTraceToStderr 24from repo_trace import IsTraceToStderr
25 25
26_NOT_TTY = not os.isatty(2) 26_TTY = sys.stderr.isatty()
27 27
28# This will erase all content in the current line (wherever the cursor is). 28# This will erase all content in the current line (wherever the cursor is).
29# It does not move the cursor, so this is usually followed by \r to move to 29# It does not move the cursor, so this is usually followed by \r to move to
@@ -97,7 +97,8 @@ class Progress(object):
97 self._start = time.time() 97 self._start = time.time()
98 self._show = not delay 98 self._show = not delay
99 self._units = units 99 self._units = units
100 self._elide = elide 100 self._elide = elide and _TTY
101
101 # Only show the active jobs section if we run more than one in parallel. 102 # Only show the active jobs section if we run more than one in parallel.
102 self._show_jobs = False 103 self._show_jobs = False
103 self._active = 0 104 self._active = 0
@@ -129,7 +130,7 @@ class Progress(object):
129 def _write(self, s): 130 def _write(self, s):
130 s = "\r" + s 131 s = "\r" + s
131 if self._elide: 132 if self._elide:
132 col = os.get_terminal_size().columns 133 col = os.get_terminal_size(sys.stderr.fileno()).columns
133 if len(s) > col: 134 if len(s) > col:
134 s = s[: col - 1] + ".." 135 s = s[: col - 1] + ".."
135 sys.stderr.write(s) 136 sys.stderr.write(s)
@@ -157,7 +158,7 @@ class Progress(object):
157 msg = self._last_msg 158 msg = self._last_msg
158 self._last_msg = msg 159 self._last_msg = msg
159 160
160 if _NOT_TTY or IsTraceToStderr(): 161 if not _TTY or IsTraceToStderr():
161 return 162 return
162 163
163 elapsed_sec = time.time() - self._start 164 elapsed_sec = time.time() - self._start
@@ -199,7 +200,7 @@ class Progress(object):
199 200
200 def end(self): 201 def end(self):
201 self._update_event.set() 202 self._update_event.set()
202 if _NOT_TTY or IsTraceToStderr() or not self._show: 203 if not _TTY or IsTraceToStderr() or not self._show:
203 return 204 return
204 205
205 duration = duration_str(time.time() - self._start) 206 duration = duration_str(time.time() - self._start)