OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env 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 """Script to download sdk/extras packages on the bots from google storage. | 6 """Script to download sdk/extras packages on the bots from google storage. |
7 | 7 |
8 The script expects arguments that specify zips file in the google storage | 8 The script expects arguments that specify zips file in the google storage |
9 bucket named: <dir in SDK extras>_<package name>_<version>.zip. The file will | 9 bucket named: <dir in SDK extras>_<package name>_<version>.zip. The file will |
10 be extracted in the android_tools/sdk/extras directory on the test bots. This | 10 be extracted in the android_tools/sdk/extras directory on the test bots. This |
(...skipping 27 matching lines...) Expand all Loading... | |
38 | 38 |
39 def clean_and_extract(dir_name, package_name, zip_file): | 39 def clean_and_extract(dir_name, package_name, zip_file): |
40 local_dir = '%s/%s/%s' % (SDK_EXTRAS_PATH, dir_name, package_name) | 40 local_dir = '%s/%s/%s' % (SDK_EXTRAS_PATH, dir_name, package_name) |
41 if os.path.exists(local_dir): | 41 if os.path.exists(local_dir): |
42 shutil.rmtree(local_dir) | 42 shutil.rmtree(local_dir) |
43 local_zip = '%s/%s' % (SDK_EXTRAS_PATH, zip_file) | 43 local_zip = '%s/%s' % (SDK_EXTRAS_PATH, zip_file) |
44 with zipfile.ZipFile(local_zip) as z: | 44 with zipfile.ZipFile(local_zip) as z: |
45 z.extractall(path=SDK_EXTRAS_PATH) | 45 z.extractall(path=SDK_EXTRAS_PATH) |
46 | 46 |
47 | 47 |
48 def download_package(remote_file, local_file): | |
49 """Download a file from GCS. | |
50 | |
51 Returns: | |
52 success (bool): True if the download succeeded, False otherwise. | |
53 """ | |
54 if not os.path.exists(local_file): | |
Dirk Pranke
2015/07/31 00:35:59
it's confusing to me that a routine called downloa
| |
55 try: | |
56 subprocess.check_call(['python', GSUTIL_PATH, '--force-version', '4.7', | |
57 'cp', remote_file, local_file]) | |
58 except subprocess.CalledProcessError: | |
59 print ('WARNING: Failed to download SDK packages. If this bot compiles ' | |
60 'for Android, it may have errors.') | |
61 return False | |
62 return True | |
63 | |
48 def main(): | 64 def main(): |
49 if not os.environ.get('CHROME_HEADLESS'): | 65 if not os.environ.get('CHROME_HEADLESS'): |
50 # This is not a buildbot checkout. | 66 # This is not a buildbot checkout. |
51 return 0 | 67 return 0 |
52 # Update the android_sdk_extras.json file to update downloaded packages. | 68 # Update the android_sdk_extras.json file to update downloaded packages. |
53 with open(SDK_EXTRAS_JSON_FILE) as json_file: | 69 with open(SDK_EXTRAS_JSON_FILE) as json_file: |
54 packages = json.load(json_file) | 70 packages = json.load(json_file) |
55 for package in packages: | 71 for package in packages: |
56 local_zip = '%s/%s' % (SDK_EXTRAS_PATH, package['zip']) | 72 local_zip = '%s/%s' % (SDK_EXTRAS_PATH, package['zip']) |
57 if not os.path.exists(local_zip): | 73 package_zip = '%s/%s' % (SDK_EXTRAS_BUCKET, package['zip']) |
58 package_zip = '%s/%s' % (SDK_EXTRAS_BUCKET, package['zip']) | 74 for attempt in xrange(2): |
75 print '(%d) Downloading package %s' % (attempt + 1, package['zip']) | |
76 if not download_package(package_zip, local_zip): | |
77 return 0 # hiding downloading failures on purpose. | |
Dirk Pranke
2015/07/31 00:35:59
I don't know what "hiding" means in this context,
| |
59 try: | 78 try: |
60 subprocess.check_call(['python', GSUTIL_PATH, '--force-version', '4.7', | 79 # Always clean dir and extract zip to ensure correct contents. |
61 'cp', package_zip, local_zip]) | 80 clean_and_extract(package['dir_name'], |
62 except subprocess.CalledProcessError: | 81 package['package'], |
63 print ('WARNING: Failed to download SDK packages. If this bot compiles ' | 82 package['zip']) |
64 'for Android, it may have errors.') | 83 break |
65 return 0 | 84 except zipfile.BadZipfile: |
66 # Always clean dir and extract zip to ensure correct contents. | 85 print 'Failed unpacking zip file. Deleting and retrying...' |
67 clean_and_extract(package['dir_name'], package['package'], package['zip']) | 86 os.remove(local_zip) |
87 continue | |
Dirk Pranke
2015/07/31 00:35:59
this continue is unnecessary, no?
| |
88 | |
89 else: | |
90 print ('WARNING: Failed to unpack SDK packages. If this bot compiles ' | |
91 'for Android, it may have errors.') | |
92 return 1 | |
68 | 93 |
69 | 94 |
70 if __name__ == '__main__': | 95 if __name__ == '__main__': |
71 sys.exit(main()) | 96 sys.exit(main()) |
OLD | NEW |