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. | 10 be extracted in the android_tools/sdk/extras directory. |
11 """ | 11 """ |
12 | 12 |
| 13 import json |
13 import os | 14 import os |
14 import shutil | 15 import shutil |
15 import subprocess | 16 import subprocess |
16 import sys | 17 import sys |
17 import zipfile | 18 import zipfile |
18 | 19 |
19 sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'android')) | 20 sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'android')) |
20 from pylib import constants | 21 from pylib import constants |
21 | 22 |
22 GSUTIL_PATH = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, | 23 GSUTIL_PATH = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, |
23 os.pardir, os.pardir, os.pardir, os.pardir, 'depot_tools', 'gsutil.py') | 24 os.pardir, os.pardir, os.pardir, os.pardir, 'depot_tools', 'gsutil.py') |
24 SDK_EXTRAS_BUCKET = 'gs://chrome-sdk-extras' | 25 SDK_EXTRAS_BUCKET = 'gs://chrome-sdk-extras' |
25 SDK_EXTRAS_PATH = os.path.join(constants.ANDROID_SDK_ROOT, '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') |
26 | 29 |
27 | 30 |
28 def clean_and_extract(zip_file): | 31 def clean_and_extract(dir_name, package_name, zip_file): |
29 # Extract the directory name and package name from zip file name. The format | |
30 # of the zip file is <dir in sdk/extras>_<package_name>_<version>.zip. | |
31 dir_name = zip_file[:zip_file.index('_')] | |
32 package_name = zip_file[zip_file.index('_')+1:zip_file.rindex('_')] | |
33 local_dir = '%s/%s/%s' % (SDK_EXTRAS_PATH, dir_name, package_name) | 32 local_dir = '%s/%s/%s' % (SDK_EXTRAS_PATH, dir_name, package_name) |
34 if os.path.exists(local_dir): | 33 if os.path.exists(local_dir): |
35 shutil.rmtree(local_dir) | 34 shutil.rmtree(local_dir) |
36 local_zip = '%s/%s' % (SDK_EXTRAS_PATH, zip_file) | 35 local_zip = '%s/%s' % (SDK_EXTRAS_PATH, zip_file) |
37 with zipfile.ZipFile(local_zip) as z: | 36 with zipfile.ZipFile(local_zip) as z: |
38 z.extractall(path=SDK_EXTRAS_PATH) | 37 z.extractall(path=SDK_EXTRAS_PATH) |
39 | 38 |
40 | 39 |
41 def main(args): | 40 def main(): |
42 if not os.path.exists(GSUTIL_PATH) or not os.path.exists(SDK_EXTRAS_PATH): | 41 if not os.path.exists(GSUTIL_PATH) or not os.path.exists(SDK_EXTRAS_PATH): |
43 # This is not a buildbot checkout. | 42 # This is not a buildbot checkout. |
44 return 0 | 43 return 0 |
45 for arg in args[1:]: | 44 # Update the android_sdk_extras.json file to update downloaded packages. |
46 local_zip = '%s/%s' % (SDK_EXTRAS_PATH, arg) | 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']) |
47 if not os.path.exists(local_zip): | 49 if not os.path.exists(local_zip): |
48 package_zip = '%s/%s' % (SDK_EXTRAS_BUCKET, arg) | 50 package_zip = '%s/%s' % (SDK_EXTRAS_BUCKET, package['zip']) |
49 subprocess.check_call([GSUTIL_PATH, '--force-version', '4.7', 'cp', | 51 subprocess.check_call([GSUTIL_PATH, '--force-version', '4.7', 'cp', |
50 package_zip, local_zip]) | 52 package_zip, local_zip]) |
51 # Always clean dir and extract zip to ensure correct contents. | 53 # Always clean dir and extract zip to ensure correct contents. |
52 clean_and_extract(arg) | 54 clean_and_extract(package['dir_name'], package['package'], package['zip']) |
53 | 55 |
54 | 56 |
55 if __name__ == '__main__': | 57 if __name__ == '__main__': |
56 sys.exit(main(sys.argv)) | 58 sys.exit(main()) |
OLD | NEW |