| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """ | 6 """ |
| 7 Downloads Go binaries from Google Cloud Storage and extracts them to | 7 Downloads Go binaries from Google Cloud Storage and extracts them to |
| 8 INSTALL_DIR, updating INSTALL_DIR/VERSION stamp file with current version. | 8 INSTALL_DIR, updating INSTALL_DIR/VERSION stamp file with current version. |
| 9 Does nothing if INSTALL_DIR/VERSION is already up to date. | 9 Does nothing if INSTALL_DIR/VERSION is already up to date. |
| 10 """ | 10 """ |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 def InstallGoBinaries(version): | 55 def InstallGoBinaries(version): |
| 56 """Downloads zipped go binaries from Google Cloud Storage and extracts them, | 56 """Downloads zipped go binaries from Google Cloud Storage and extracts them, |
| 57 stamping current version.""" | 57 stamping current version.""" |
| 58 | 58 |
| 59 # Remove current installation. | 59 # Remove current installation. |
| 60 if os.path.exists(INSTALL_DIR): | 60 if os.path.exists(INSTALL_DIR): |
| 61 shutil.rmtree(INSTALL_DIR) | 61 shutil.rmtree(INSTALL_DIR) |
| 62 os.mkdir(INSTALL_DIR) | 62 os.mkdir(INSTALL_DIR) |
| 63 # Download go tool binaries from GCS. | 63 # Download go tool binaries from GCS. |
| 64 archive_path = os.path.join(INSTALL_DIR, 'go.tar.gz') | 64 archive_path = os.path.join(INSTALL_DIR, 'go.tar.gz') |
| 65 download_cmd = ['python', GSUTIL_PATH, '-b', 'cp', | 65 download_cmd = ['python', GSUTIL_PATH, 'cp', |
| 66 'gs://mojo/go/tool/%s.tar.gz' % version, | 66 'gs://mojo/go/tool/%s.tar.gz' % version, |
| 67 archive_path] | 67 archive_path] |
| 68 if not RunCommand(download_cmd): | 68 if not RunCommand(download_cmd): |
| 69 print ('WARNING: Failed to download Go tool binaries.') | 69 print ('WARNING: Failed to download Go tool binaries.') |
| 70 return | 70 return |
| 71 | 71 |
| 72 print "Extracting Go binaries." | 72 print "Extracting Go binaries." |
| 73 with tarfile.open(archive_path) as arch: | 73 with tarfile.open(archive_path) as arch: |
| 74 arch.extractall(INSTALL_DIR) | 74 arch.extractall(INSTALL_DIR) |
| 75 os.remove(archive_path) | 75 os.remove(archive_path) |
| 76 # Write version as the last step. | 76 # Write version as the last step. |
| 77 with open(os.path.join(INSTALL_DIR, VersionFileName()), 'w+') as f: | 77 with open(os.path.join(INSTALL_DIR, VersionFileName()), 'w+') as f: |
| 78 f.write('%s\n' % version) | 78 f.write('%s\n' % version) |
| 79 | 79 |
| 80 def main(): | 80 def main(): |
| 81 # Read latest version. | 81 # Read latest version. |
| 82 version = '' | 82 version = '' |
| 83 with open(os.path.join(THIS_DIR, VersionFileName())) as f: | 83 with open(os.path.join(THIS_DIR, VersionFileName())) as f: |
| 84 version = f.read().strip() | 84 version = f.read().strip() |
| 85 # Return if installed binaries are up to date. | 85 # Return if installed binaries are up to date. |
| 86 if version == GetInstalledVersion(): | 86 if version == GetInstalledVersion(): |
| 87 return | 87 return |
| 88 InstallGoBinaries(version) | 88 InstallGoBinaries(version) |
| 89 | 89 |
| 90 if __name__ == '__main__': | 90 if __name__ == '__main__': |
| 91 sys.exit(main()) | 91 sys.exit(main()) |
| OLD | NEW |