Bug 1286799 - mozboot: Unbuffer stdout. r=gps
Reopen sys.stdout in unbuffered mode so we can correctly print
'Checking foo... Result' in two parts without calling sys.stdout.flush()
everywhere.
Although we import print_function from the future, the python 2 version
does not support the python 3 flush=True argument.
MozReview-Commit-ID: SjliWeoSa3
--- a/python/mozboot/mozboot/rust.py
+++ b/python/mozboot/mozboot/rust.py
@@ -118,41 +118,43 @@ def http_download_and_hash(url):
break
return h.hexdigest()
def make_checksums(version, validate=False):
hashes = []
for platform in RUSTUP_HASHES.keys():
if validate:
print('Checking %s... ' % platform, end='')
- sys.stdout.flush()
else:
print('Fetching %s... ' % platform, end='')
- sys.stdout.flush()
checksum = http_download_and_hash(rustup_url(platform, version))
if validate and checksum != rustup_hash(platform):
print('mismatch:\n script: %s\n server: %s' % (
RUSTUP_HASHES[platform], checksum))
else:
print('OK')
hashes.append((platform, checksum))
return hashes
if __name__ == '__main__':
'''Allow invoking the module as a utility to update checksums.'''
+
+ # Unbuffer stdout so our two-part 'Checking...' messages print correctly
+ # even if there's network delay.
+ sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
+
update = False
if len(sys.argv) > 1:
if sys.argv[1] == '--update':
update = True
else:
print(USAGE)
sys.exit(1)
print('Checking latest installer version... ', end='')
- sys.stdout.flush()
version = rustup_latest_version()
if not version:
print('ERROR: Could not query current rustup installer version.')
sys.exit(1)
print(version)
if version == RUSTUP_VERSION:
print("We're up to date. Validating checksums.")