| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 # Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
| 3 # | 3 # |
| 4 # Use of this source code is governed by a BSD-style license | 4 # Use of this source code is governed by a BSD-style license |
| 5 # that can be found in the LICENSE file in the root of the source | 5 # that can be found in the LICENSE file in the root of the source |
| 6 # tree. An additional intellectual property rights grant can be found | 6 # tree. An additional intellectual property rights grant can be found |
| 7 # in the file PATENTS. All contributing project authors may | 7 # in the file PATENTS. All contributing project authors may |
| 8 # be found in the AUTHORS file in the root of the source tree. | 8 # be found in the AUTHORS file in the root of the source tree. |
| 9 | 9 |
| 10 """Utilities for all our deps-management stuff.""" | 10 """Utilities for all our deps-management stuff.""" |
| 11 | 11 |
| 12 import hashlib | |
| 13 import os | 12 import os |
| 14 import shutil | 13 import shutil |
| 15 import sys | 14 import sys |
| 16 import subprocess | 15 import subprocess |
| 17 import tarfile | 16 import tarfile |
| 18 import time | 17 import time |
| 19 import zipfile | 18 import zipfile |
| 20 | 19 |
| 21 | 20 |
| 22 def RunSubprocessWithRetry(cmd): | 21 def RunSubprocessWithRetry(cmd): |
| 23 """Invokes the subprocess and backs off exponentially on fail.""" | 22 """Invokes the subprocess and backs off exponentially on fail.""" |
| 24 for i in range(5): | 23 for i in range(5): |
| 25 try: | 24 try: |
| 26 subprocess.check_call(cmd) | 25 subprocess.check_call(cmd) |
| 27 return | 26 return |
| 28 except subprocess.CalledProcessError as exception: | 27 except subprocess.CalledProcessError as exception: |
| 29 backoff = pow(2, i) | 28 backoff = pow(2, i) |
| 30 print 'Got %s, retrying in %d seconds...' % (exception, backoff) | 29 print 'Got %s, retrying in %d seconds...' % (exception, backoff) |
| 31 time.sleep(backoff) | 30 time.sleep(backoff) |
| 32 | 31 |
| 33 print 'Giving up.' | 32 print 'Giving up.' |
| 34 raise exception | 33 raise exception |
| 35 | 34 |
| 36 | 35 |
| 37 def DownloadFilesFromGoogleStorage(path): | 36 def DownloadFilesFromGoogleStorage(path, auto_platform=True): |
| 38 print 'Downloading files in %s...' % path | 37 print 'Downloading files in %s...' % path |
| 39 | 38 |
| 40 extension = 'bat' if 'win32' in sys.platform else 'py' | 39 extension = 'bat' if 'win32' in sys.platform else 'py' |
| 41 cmd = ['download_from_google_storage.%s' % extension, | 40 cmd = ['download_from_google_storage.%s' % extension, |
| 42 '--bucket=chromium-webrtc-resources', | 41 '--bucket=chromium-webrtc-resources', |
| 43 '--auto_platform', | |
| 44 '--recursive', | |
| 45 '--directory', path] | 42 '--directory', path] |
| 43 if auto_platform: |
| 44 cmd += ['--auto_platform', '--recursive'] |
| 46 subprocess.check_call(cmd) | 45 subprocess.check_call(cmd) |
| 47 | 46 |
| 48 | 47 |
| 49 def ComputeSHA1(path): | |
| 50 if not os.path.exists(path): | |
| 51 return 0 | |
| 52 | |
| 53 sha1 = hashlib.sha1() | |
| 54 file_to_hash = open(path, 'rb') | |
| 55 try: | |
| 56 sha1.update(file_to_hash.read()) | |
| 57 finally: | |
| 58 file_to_hash.close() | |
| 59 | |
| 60 return sha1.hexdigest() | |
| 61 | |
| 62 | |
| 63 # Code partially copied from | 48 # Code partially copied from |
| 64 # https://cs.chromium.org#chromium/build/scripts/common/chromium_utils.py | 49 # https://cs.chromium.org#chromium/build/scripts/common/chromium_utils.py |
| 65 def RemoveDirectory(*path): | 50 def RemoveDirectory(*path): |
| 66 """Recursively removes a directory, even if it's marked read-only. | 51 """Recursively removes a directory, even if it's marked read-only. |
| 67 | 52 |
| 68 Remove the directory located at *path, if it exists. | 53 Remove the directory located at *path, if it exists. |
| 69 | 54 |
| 70 shutil.rmtree() doesn't work on Windows if any of the files or directories | 55 shutil.rmtree() doesn't work on Windows if any of the files or directories |
| 71 are read-only, which svn repositories and some .svn files are. We need to | 56 are read-only, which svn repositories and some .svn files are. We need to |
| 72 be able to force the files to be writable (i.e., deletable) as we traverse | 57 be able to force the files to be writable (i.e., deletable) as we traverse |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 111 |
| 127 | 112 |
| 128 def GetPlatform(): | 113 def GetPlatform(): |
| 129 if sys.platform.startswith('win'): | 114 if sys.platform.startswith('win'): |
| 130 return 'win' | 115 return 'win' |
| 131 if sys.platform.startswith('linux'): | 116 if sys.platform.startswith('linux'): |
| 132 return 'linux' | 117 return 'linux' |
| 133 if sys.platform.startswith('darwin'): | 118 if sys.platform.startswith('darwin'): |
| 134 return 'mac' | 119 return 'mac' |
| 135 raise Exception("Can't run on platform %s." % sys.platform) | 120 raise Exception("Can't run on platform %s." % sys.platform) |
| OLD | NEW |