Permalink
Browse files

Reduce log spam when running sdkmanager

  • Loading branch information...
SimonSapin committed Oct 11, 2018
1 parent 6c82c47 commit f0d8e8af49639678d1bd4d99855ae70737615a7a
Showing with 29 additions and 6 deletions.
  1. +29 −6 python/servo/bootstrap_commands.py
@@ -163,8 +163,35 @@ def download(target_dir, name, flatten=False):
sdkmanager = [path.join(toolchains, "sdk", "tools", "bin", "sdkmanager")] + components
if accept_all_licences:
yes = subprocess.Popen(["yes"], stdout=subprocess.PIPE)
subprocess.check_call(sdkmanager, stdin=yes.stdout)
process = subprocess.Popen(
sdkmanager, stdin=yes.stdout, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
)
# Reduce progress bar spam by removing duplicate lines.
# Printing the same line again with \r is a no-op in a real terminal,
# but each line is shown individually in Taskcluster's log viewer.
previous_line = None
line = b""
while 1:
# Read one byte at a time because in Python:
# * readline() blocks until "\n", which doesn't come before the prompt
# * read() blocks until EOF, which doesn't come before the prompt
# * read(n) keeps reading until it gets n bytes or EOF,
# but we don't know reliably how many bytes to read until the prompt
byte = process.stdout.read(1)
if len(byte) == 0:
print(line)
break
line += byte
if byte == b'\n' or byte == b'\r':
if line != previous_line:
print(line.decode("utf-8", "replace"), end="")
sys.stdout.flush()
previous_line = line
line = b""
exit_code = process.wait()
yes.terminate()
if exit_code:
return exit_code
else:
subprocess.check_call(sdkmanager)
@@ -180,11 +207,7 @@ def download(target_dir, name, flatten=False):
])
output = b""
while 1:
# Read one byte at a time because in Python:
# * readline() blocks until "\n", which doesn't come before the prompt
# * read() blocks until EOF, which doesn't come before the prompt
# * read(n) keeps reading until it gets n bytes or EOF,
# but we don't know reliably how many bytes to read until the prompt
# Read one byte at a time, see comment above.
byte = process.stdout.read(1)
if len(byte) == 0:
break

0 comments on commit f0d8e8a

Please sign in to comment.