OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 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 """Utilities for all our deps-management stuff.""" | 6 """Utilities for all our deps-management stuff.""" |
7 | 7 |
8 import hashlib | 8 import hashlib |
9 import os | 9 import os |
10 import shutil | 10 import shutil |
11 import sys | 11 import sys |
12 import subprocess | 12 import subprocess |
13 import tarfile | 13 import tarfile |
| 14 import time |
14 import zipfile | 15 import zipfile |
15 | 16 |
16 | 17 |
| 18 def RunSubprocessWithRetry(cmd): |
| 19 """Invokes the subprocess and backs off exponentially on fail.""" |
| 20 for i in range(5): |
| 21 try: |
| 22 subprocess.check_call(cmd) |
| 23 return |
| 24 except subprocess.CalledProcessError as exception: |
| 25 backoff = pow(2, i) |
| 26 print 'Got %s, retrying in %d seconds...' % (exception, backoff) |
| 27 time.sleep(backoff) |
| 28 |
| 29 print 'Giving up.' |
| 30 raise exception |
| 31 |
| 32 |
17 def DownloadFilesFromGoogleStorage(path): | 33 def DownloadFilesFromGoogleStorage(path): |
18 print 'Downloading files in %s...' % path | 34 print 'Downloading files in %s...' % path |
19 | 35 |
20 extension = 'bat' if 'win32' in sys.platform else 'py' | 36 extension = 'bat' if 'win32' in sys.platform else 'py' |
21 cmd = ['download_from_google_storage.%s' % extension, | 37 cmd = ['download_from_google_storage.%s' % extension, |
22 '--bucket=chromium-webrtc-resources', | 38 '--bucket=chromium-webrtc-resources', |
23 '--auto_platform', | 39 '--auto_platform', |
24 '--recursive', | 40 '--recursive', |
25 '--directory', path] | 41 '--directory', path] |
26 subprocess.check_call(cmd) | 42 subprocess.check_call(cmd) |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 | 92 |
77 def GetPlatform(): | 93 def GetPlatform(): |
78 if sys.platform.startswith('win'): | 94 if sys.platform.startswith('win'): |
79 return 'win' | 95 return 'win' |
80 if sys.platform.startswith('linux'): | 96 if sys.platform.startswith('linux'): |
81 return 'linux' | 97 return 'linux' |
82 if sys.platform.startswith('darwin'): | 98 if sys.platform.startswith('darwin'): |
83 return 'mac' | 99 return 'mac' |
84 raise Exception("Can't run on platform %s." % sys.platform) | 100 raise Exception("Can't run on platform %s." % sys.platform) |
85 | 101 |
OLD | NEW |