JSONStringValueSerializer takes a StringPiece instead of std::string&.
[chromium-blink-merge.git] / build / download_sdk_extras.py
blobd38ee8651de5833924ea402c599ed80b10947583
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.
6 """Script to download sdk/extras packages on the bots from 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
10 be extracted in the android_tools/sdk/extras directory.
11 """
13 import json
14 import os
15 import shutil
16 import subprocess
17 import sys
18 import zipfile
20 sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'android'))
21 from pylib import constants
23 GSUTIL_PATH = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir,
24 os.pardir, os.pardir, os.pardir, os.pardir, 'depot_tools', 'gsutil.py')
25 SDK_EXTRAS_BUCKET = 'gs://chrome-sdk-extras'
26 SDK_EXTRAS_PATH = os.path.join(constants.ANDROID_SDK_ROOT, 'extras')
27 SDK_EXTRAS_JSON_FILE = os.path.join(os.path.dirname(__file__),
28 'android_sdk_extras.json')
31 def clean_and_extract(dir_name, package_name, zip_file):
32 local_dir = '%s/%s/%s' % (SDK_EXTRAS_PATH, dir_name, package_name)
33 if os.path.exists(local_dir):
34 shutil.rmtree(local_dir)
35 local_zip = '%s/%s' % (SDK_EXTRAS_PATH, zip_file)
36 with zipfile.ZipFile(local_zip) as z:
37 z.extractall(path=SDK_EXTRAS_PATH)
40 def main():
41 if not os.path.exists(GSUTIL_PATH) or not os.path.exists(SDK_EXTRAS_PATH):
42 # This is not a buildbot checkout.
43 return 0
44 # Update the android_sdk_extras.json file to update downloaded packages.
45 with open(SDK_EXTRAS_JSON_FILE) as json_file:
46 packages = json.load(json_file)
47 for package in packages:
48 local_zip = '%s/%s' % (SDK_EXTRAS_PATH, package['zip'])
49 if not os.path.exists(local_zip):
50 package_zip = '%s/%s' % (SDK_EXTRAS_BUCKET, package['zip'])
51 subprocess.check_call([GSUTIL_PATH, '--force-version', '4.7', 'cp',
52 package_zip, local_zip])
53 # Always clean dir and extract zip to ensure correct contents.
54 clean_and_extract(package['dir_name'], package['package'], package['zip'])
57 if __name__ == '__main__':
58 sys.exit(main())