blob: 45e71996f1f545f02b0a3c6dda6a5daa3450da8f [file] [log] [blame]
Nick Bray27a3f6e2015-01-08 16:39:35 -08001#!/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
8The script expects arguments that specify zips file in the google storage
9bucket named: <dir in SDK extras>_<package name>_<version>.zip. The file will
Etienne Membrives386015a2015-02-19 17:27:12 +010010be extracted in the android_tools/sdk/extras directory on the test bots. This
11script will not do anything for developers.
Nick Bray27a3f6e2015-01-08 16:39:35 -080012"""
13
14import json
15import os
16import shutil
17import subprocess
18import sys
19import zipfile
20
Etienne Membrives386015a2015-02-19 17:27:12 +010021SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
22CHROME_SRC = os.path.abspath(os.path.join(SCRIPT_DIR, os.pardir))
23sys.path.insert(0, os.path.join(SCRIPT_DIR, 'android'))
24sys.path.insert(1, os.path.join(CHROME_SRC, 'tools'))
Nick Bray27a3f6e2015-01-08 16:39:35 -080025
Etienne Membrives386015a2015-02-19 17:27:12 +010026from pylib import constants
27import find_depot_tools
28
29DEPOT_PATH = find_depot_tools.add_depot_tools_to_path()
30GSUTIL_PATH = os.path.join(DEPOT_PATH, 'gsutil.py')
Nick Bray27a3f6e2015-01-08 16:39:35 -080031SDK_EXTRAS_BUCKET = 'gs://chrome-sdk-extras'
32SDK_EXTRAS_PATH = os.path.join(constants.ANDROID_SDK_ROOT, 'extras')
33SDK_EXTRAS_JSON_FILE = os.path.join(os.path.dirname(__file__),
34 'android_sdk_extras.json')
35
36
37def 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
46def main():
Etienne Membrives386015a2015-02-19 17:27:12 +010047 if not os.environ.get('CHROME_HEADLESS'):
Nick Bray27a3f6e2015-01-08 16:39:35 -080048 # 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 Seidel101a5332015-02-23 14:42:04 -080057 subprocess.check_call(['python', GSUTIL_PATH, '--force-version', '4.7',
58 'cp', package_zip, local_zip])
Nick Bray27a3f6e2015-01-08 16:39:35 -080059 # Always clean dir and extract zip to ensure correct contents.
60 clean_and_extract(package['dir_name'], package['package'], package['zip'])
61
62
63if __name__ == '__main__':
64 sys.exit(main())