Bug 1286799 - mozboot: Unbuffer stdout. r=gps draft
authorRalph Giles <giles@mozilla.com>
Thu, 17 Nov 2016 15:21:39 -0800
changeset 442190 3d58caa72b32cdeaf4c830c260b301ebb2b566de
parent 442189 1b7793724c6f8044abcb4cee74e3a4964eb61ef1
child 442191 d03baa9c20d4049bcb9483d0f23dab8db800327f
push id36622
push userbmo:giles@thaumas.net
push dateTue, 22 Nov 2016 01:00:21 +0000
reviewersgps
bugs1286799
milestone53.0a1
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
python/mozboot/mozboot/rust.py
--- 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.")