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. |
hinoka
2015/02/17 21:29:08
Add something about how this isn't for public cons
navabi
2015/02/17 21:44:05
Done.
| |
11 """ | 11 """ |
12 | 12 |
13 import json | 13 import json |
14 import os | 14 import os |
15 import shutil | 15 import shutil |
16 import subprocess | 16 import subprocess |
17 import sys | 17 import sys |
18 import zipfile | 18 import zipfile |
19 | 19 |
20 sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'android')) | 20 script_dir = os.path.dirname(os.path.realpath(__file__)) |
kjellander_chromium
2015/02/17 21:32:59
These variables are usually uppercase (constants),
navabi
2015/02/17 21:44:05
Done.
| |
21 chrome_src = os.path.abspath(os.path.join(script_dir, os.pardir)) | |
22 sys.path.insert(0, os.path.join(script_dir, 'android')) | |
21 from pylib import constants | 23 from pylib import constants |
nyquist
2015/02/17 21:37:05
Nit: Could this be moved one line down? I find it
navabi
2015/02/17 21:44:05
Done.
| |
24 sys.path.insert(1, os.path.join(chrome_src, 'tools')) | |
25 import find_depot_tools | |
22 | 26 |
23 GSUTIL_PATH = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, | 27 DEPOT_PATH = find_depot_tools.add_depot_tools_to_path() |
24 os.pardir, os.pardir, os.pardir, os.pardir, 'depot_tools', 'gsutil.py') | 28 GSUTIL_PATH = os.path.join(DEPOT_PATH, 'gsutil.py') |
25 SDK_EXTRAS_BUCKET = 'gs://chrome-sdk-extras' | 29 SDK_EXTRAS_BUCKET = 'gs://chrome-sdk-extras' |
26 SDK_EXTRAS_PATH = os.path.join(constants.ANDROID_SDK_ROOT, 'extras') | 30 SDK_EXTRAS_PATH = os.path.join(constants.ANDROID_SDK_ROOT, 'extras') |
27 SDK_EXTRAS_JSON_FILE = os.path.join(os.path.dirname(__file__), | 31 SDK_EXTRAS_JSON_FILE = os.path.join(os.path.dirname(__file__), |
28 'android_sdk_extras.json') | 32 'android_sdk_extras.json') |
29 | 33 |
30 | 34 |
31 def clean_and_extract(dir_name, package_name, zip_file): | 35 def clean_and_extract(dir_name, package_name, zip_file): |
32 local_dir = '%s/%s/%s' % (SDK_EXTRAS_PATH, dir_name, package_name) | 36 local_dir = '%s/%s/%s' % (SDK_EXTRAS_PATH, dir_name, package_name) |
33 if os.path.exists(local_dir): | 37 if os.path.exists(local_dir): |
34 shutil.rmtree(local_dir) | 38 shutil.rmtree(local_dir) |
35 local_zip = '%s/%s' % (SDK_EXTRAS_PATH, zip_file) | 39 local_zip = '%s/%s' % (SDK_EXTRAS_PATH, zip_file) |
36 with zipfile.ZipFile(local_zip) as z: | 40 with zipfile.ZipFile(local_zip) as z: |
37 z.extractall(path=SDK_EXTRAS_PATH) | 41 z.extractall(path=SDK_EXTRAS_PATH) |
38 | 42 |
39 | 43 |
40 def main(): | 44 def main(): |
41 if not os.path.exists(GSUTIL_PATH) or not os.path.exists(SDK_EXTRAS_PATH): | 45 if not os.environ.get('CHROME_HEADLESS'): |
hinoka
2015/02/17 20:34:01
Or just check if GSUTIL_PATH exists?
we try to av
navabi
2015/02/17 20:38:24
I did that before. But this does not work on WebRT
hinoka
2015/02/17 20:40:59
Is switching to "find_depot_tools" sufficient?
navabi
2015/02/17 20:45:39
No. Because it will find_depot_tools for developer
hinoka
2015/02/17 21:29:08
Oh I see, auth issue.
| |
42 # This is not a buildbot checkout. | 46 # This is not a buildbot checkout. |
43 return 0 | 47 return 0 |
44 # Update the android_sdk_extras.json file to update downloaded packages. | 48 # Update the android_sdk_extras.json file to update downloaded packages. |
45 with open(SDK_EXTRAS_JSON_FILE) as json_file: | 49 with open(SDK_EXTRAS_JSON_FILE) as json_file: |
46 packages = json.load(json_file) | 50 packages = json.load(json_file) |
47 for package in packages: | 51 for package in packages: |
48 local_zip = '%s/%s' % (SDK_EXTRAS_PATH, package['zip']) | 52 local_zip = '%s/%s' % (SDK_EXTRAS_PATH, package['zip']) |
49 if not os.path.exists(local_zip): | 53 if not os.path.exists(local_zip): |
50 package_zip = '%s/%s' % (SDK_EXTRAS_BUCKET, package['zip']) | 54 package_zip = '%s/%s' % (SDK_EXTRAS_BUCKET, package['zip']) |
51 subprocess.check_call([GSUTIL_PATH, '--force-version', '4.7', 'cp', | 55 subprocess.check_call([GSUTIL_PATH, '--force-version', '4.7', 'cp', |
52 package_zip, local_zip]) | 56 package_zip, local_zip]) |
53 # Always clean dir and extract zip to ensure correct contents. | 57 # Always clean dir and extract zip to ensure correct contents. |
54 clean_and_extract(package['dir_name'], package['package'], package['zip']) | 58 clean_and_extract(package['dir_name'], package['package'], package['zip']) |
55 | 59 |
56 | 60 |
57 if __name__ == '__main__': | 61 if __name__ == '__main__': |
58 sys.exit(main()) | 62 sys.exit(main()) |
OLD | NEW |