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 if not os.path.exists(local_file): | |
50 try: | |
51 subprocess.check_call(['python', GSUTIL_PATH, '--force-version', '4.7', | |
52 'cp', remote_file, local_file]) | |
53 except subprocess.CalledProcessError: | |
54 print ('WARNING: Failed to download SDK packages. If this bot compiles ' | |
55 'for Android, it may have errors.') | |
56 return 0 | |
57 | |
58 | |
48 def main(): | 59 def main(): |
49 if not os.environ.get('CHROME_HEADLESS'): | 60 if not os.environ.get('CHROME_HEADLESS'): |
50 # This is not a buildbot checkout. | 61 # This is not a buildbot checkout. |
51 return 0 | 62 return 0 |
52 # Update the android_sdk_extras.json file to update downloaded packages. | 63 # Update the android_sdk_extras.json file to update downloaded packages. |
53 with open(SDK_EXTRAS_JSON_FILE) as json_file: | 64 with open(SDK_EXTRAS_JSON_FILE) as json_file: |
54 packages = json.load(json_file) | 65 packages = json.load(json_file) |
55 for package in packages: | 66 for package in packages: |
56 local_zip = '%s/%s' % (SDK_EXTRAS_PATH, package['zip']) | 67 local_zip = '%s/%s' % (SDK_EXTRAS_PATH, package['zip']) |
57 if not os.path.exists(local_zip): | 68 package_zip = '%s/%s' % (SDK_EXTRAS_BUCKET, package['zip']) |
58 package_zip = '%s/%s' % (SDK_EXTRAS_BUCKET, package['zip']) | 69 for attempt in xrange(2): |
70 print '(%d) Downloading package %s' % (attempt + 1, package['zip']) | |
71 download_package(package_zip, local_zip) | |
59 try: | 72 try: |
60 subprocess.check_call(['python', GSUTIL_PATH, '--force-version', '4.7', | 73 # Always clean dir and extract zip to ensure correct contents. |
61 'cp', package_zip, local_zip]) | 74 clean_and_extract(package['dir_name'], |
62 except subprocess.CalledProcessError: | 75 package['package'], |
63 print ('WARNING: Failed to download SDK packages. If this bot compiles ' | 76 package['zip']) |
64 'for Android, it may have errors.') | 77 except zipfile.BadZipfile: |
65 return 0 | 78 print 'Failed unpacking zip file. Deleting and retrying...' |
66 # Always clean dir and extract zip to ensure correct contents. | 79 os.remove(local_zip) |
67 clean_and_extract(package['dir_name'], package['package'], package['zip']) | 80 continue |
dnj
2015/07/30 22:49:03
I don't like this continue/break thing. Either bre
pgervais
2015/07/30 23:05:16
Done.
| |
81 break | |
82 else: | |
83 print ('WARNING: Failed to get SDK packages. If this bot compiles ' | |
84 'for Android, it may have errors.') | |
dnj
2015/07/30 22:49:03
This should return an error on failure.
pgervais
2015/07/30 23:05:16
Note the return 0 on line 56: it previously exited
navabi
2015/07/30 23:20:31
This will cause failures when gsutil cp fails to c
navabi
2015/07/30 23:40:39
This can not simply return an error on failure. If
dnj
2015/07/30 23:45:34
:(
| |
68 | 85 |
69 | 86 |
70 if __name__ == '__main__': | 87 if __name__ == '__main__': |
71 sys.exit(main()) | 88 sys.exit(main()) |
OLD | NEW |