Nick Bray | 27a3f6e | 2015-01-08 16:39:35 -0800 | [diff] [blame] | 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 |
Etienne Membrives | 386015a | 2015-02-19 17:27:12 +0100 | [diff] [blame] | 10 | be extracted in the android_tools/sdk/extras directory on the test bots. This |
| 11 | script will not do anything for developers. |
Nick Bray | 27a3f6e | 2015-01-08 16:39:35 -0800 | [diff] [blame] | 12 | """ |
| 13 | |
| 14 | import json |
| 15 | import os |
| 16 | import shutil |
| 17 | import subprocess |
| 18 | import sys |
| 19 | import zipfile |
| 20 | |
Etienne Membrives | 386015a | 2015-02-19 17:27:12 +0100 | [diff] [blame] | 21 | SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) |
| 22 | CHROME_SRC = os.path.abspath(os.path.join(SCRIPT_DIR, os.pardir)) |
| 23 | sys.path.insert(0, os.path.join(SCRIPT_DIR, 'android')) |
| 24 | sys.path.insert(1, os.path.join(CHROME_SRC, 'tools')) |
Nick Bray | 27a3f6e | 2015-01-08 16:39:35 -0800 | [diff] [blame] | 25 | |
Etienne Membrives | 386015a | 2015-02-19 17:27:12 +0100 | [diff] [blame] | 26 | from pylib import constants |
| 27 | import find_depot_tools |
| 28 | |
| 29 | DEPOT_PATH = find_depot_tools.add_depot_tools_to_path() |
| 30 | GSUTIL_PATH = os.path.join(DEPOT_PATH, 'gsutil.py') |
Nick Bray | 27a3f6e | 2015-01-08 16:39:35 -0800 | [diff] [blame] | 31 | SDK_EXTRAS_BUCKET = 'gs://chrome-sdk-extras' |
| 32 | SDK_EXTRAS_PATH = os.path.join(constants.ANDROID_SDK_ROOT, 'extras') |
| 33 | SDK_EXTRAS_JSON_FILE = os.path.join(os.path.dirname(__file__), |
| 34 | 'android_sdk_extras.json') |
| 35 | |
| 36 | |
| 37 | def clean_and_extract(dir_name, package_name, zip_file): |
| 38 | local_dir = '%s/%s/%s' % (SDK_EXTRAS_PATH, dir_name, package_name) |
| 39 | if os.path.exists(local_dir): |
| 40 | shutil.rmtree(local_dir) |
| 41 | local_zip = '%s/%s' % (SDK_EXTRAS_PATH, zip_file) |
| 42 | with zipfile.ZipFile(local_zip) as z: |
| 43 | z.extractall(path=SDK_EXTRAS_PATH) |
| 44 | |
| 45 | |
| 46 | def main(): |
Etienne Membrives | 386015a | 2015-02-19 17:27:12 +0100 | [diff] [blame] | 47 | if not os.environ.get('CHROME_HEADLESS'): |
Nick Bray | 27a3f6e | 2015-01-08 16:39:35 -0800 | [diff] [blame] | 48 | # This is not a buildbot checkout. |
| 49 | return 0 |
| 50 | # Update the android_sdk_extras.json file to update downloaded packages. |
| 51 | with open(SDK_EXTRAS_JSON_FILE) as json_file: |
| 52 | packages = json.load(json_file) |
| 53 | for package in packages: |
| 54 | local_zip = '%s/%s' % (SDK_EXTRAS_PATH, package['zip']) |
| 55 | if not os.path.exists(local_zip): |
| 56 | package_zip = '%s/%s' % (SDK_EXTRAS_BUCKET, package['zip']) |
Eric Seidel | 101a533 | 2015-02-23 14:42:04 -0800 | [diff] [blame^] | 57 | subprocess.check_call(['python', GSUTIL_PATH, '--force-version', '4.7', |
| 58 | 'cp', package_zip, local_zip]) |
Nick Bray | 27a3f6e | 2015-01-08 16:39:35 -0800 | [diff] [blame] | 59 | # Always clean dir and extract zip to ensure correct contents. |
| 60 | clean_and_extract(package['dir_name'], package['package'], package['zip']) |
| 61 | |
| 62 | |
| 63 | if __name__ == '__main__': |
| 64 | sys.exit(main()) |