| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 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 | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 """Script to download sdk/extras packages on the bots from google storage. | |
| 7 | |
| 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 | |
| 10 be extracted in the android_tools/sdk/extras directory on the test bots. This | |
| 11 script will not do anything for developers. | |
| 12 | |
| 13 TODO(navabi): Move this script (crbug.com/459819). | |
| 14 """ | |
| 15 | |
| 16 import json | |
| 17 import os | |
| 18 import shutil | |
| 19 import subprocess | |
| 20 import sys | |
| 21 import zipfile | |
| 22 | |
| 23 SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) | |
| 24 CHROME_SRC = os.path.abspath(os.path.join(SCRIPT_DIR, os.pardir)) | |
| 25 sys.path.insert(0, os.path.join(SCRIPT_DIR, 'android')) | |
| 26 sys.path.insert(1, os.path.join(CHROME_SRC, 'tools')) | |
| 27 | |
| 28 from pylib import constants | |
| 29 import find_depot_tools | |
| 30 | |
| 31 DEPOT_PATH = find_depot_tools.add_depot_tools_to_path() | |
| 32 GSUTIL_PATH = os.path.join(DEPOT_PATH, 'gsutil.py') | |
| 33 SDK_EXTRAS_BUCKET = 'gs://chrome-sdk-extras' | |
| 34 SDK_EXTRAS_PATH = os.path.join(constants.ANDROID_SDK_ROOT, 'extras') | |
| 35 SDK_EXTRAS_JSON_FILE = os.path.join(os.path.dirname(__file__), | |
| 36 'android_sdk_extras.json') | |
| 37 | |
| 38 | |
| 39 def clean_and_extract(dir_name, package_name, zip_file): | |
| 40 local_dir = '%s/%s/%s' % (SDK_EXTRAS_PATH, dir_name, package_name) | |
| 41 if os.path.exists(local_dir): | |
| 42 shutil.rmtree(local_dir) | |
| 43 local_zip = '%s/%s' % (SDK_EXTRAS_PATH, zip_file) | |
| 44 with zipfile.ZipFile(local_zip) as z: | |
| 45 z.extractall(path=SDK_EXTRAS_PATH) | |
| 46 | |
| 47 | |
| 48 def main(): | |
| 49 if not os.environ.get('CHROME_HEADLESS'): | |
| 50 # This is not a buildbot checkout. | |
| 51 return 0 | |
| 52 # Update the android_sdk_extras.json file to update downloaded packages. | |
| 53 with open(SDK_EXTRAS_JSON_FILE) as json_file: | |
| 54 packages = json.load(json_file) | |
| 55 for package in packages: | |
| 56 local_zip = '%s/%s' % (SDK_EXTRAS_PATH, package['zip']) | |
| 57 if not os.path.exists(local_zip): | |
| 58 package_zip = '%s/%s' % (SDK_EXTRAS_BUCKET, package['zip']) | |
| 59 try: | |
| 60 subprocess.check_call(['python', GSUTIL_PATH, '--force-version', '4.7', | |
| 61 'cp', package_zip, local_zip]) | |
| 62 except subprocess.CalledProcessError: | |
| 63 print ('WARNING: Failed to download SDK packages. If this bot compiles ' | |
| 64 'for Android, it may have errors.') | |
| 65 return 0 | |
| 66 # Always clean dir and extract zip to ensure correct contents. | |
| 67 clean_and_extract(package['dir_name'], package['package'], package['zip']) | |
| 68 | |
| 69 | |
| 70 if __name__ == '__main__': | |
| 71 sys.exit(main()) | |
| OLD | NEW |