[Password Autofill] Fix crash when triggering popup after in page navigation
[chromium-blink-merge.git] / build / download_sdk_extras.py
blob1149d9d29641a7814b6271bb53c76acdabc69db5
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 an argument that specifies the packet name in the following
9 format: <dir_in_sdk_extras>_<package_name>_<version>. There will be a
10 correpsonding bucket in google storage with that name, and it will be downloaded
11 to android_tools/sdk/extras/.
12 """
14 import os
15 import subprocess
16 import sys
18 sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'android'))
19 from pylib import constants
21 GSUTIL_PATH = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir,
22 os.pardir, os.pardir, os.pardir, os.pardir, 'depot_tools', 'gsutil.py')
23 SDK_EXTRAS_BUCKET = 'gs://chrome-sdk-extras'
24 SDK_EXTRAS_PATH = os.path.join(constants.ANDROID_SDK_ROOT, 'extras')
27 def GetCmdOutputAndStatus(cmd_lst):
28 process = subprocess.Popen(cmd_lst, stdout=subprocess.PIPE)
29 stdout, _ = process.communicate()
30 return stdout, process.returncode
32 def is_android_buildbot_checkout():
33 if not os.path.exists(GSUTIL_PATH) or not os.path.exists(SDK_EXTRAS_PATH):
34 return False
35 stdout, rc = GetCmdOutputAndStatus([GSUTIL_PATH, 'ls', SDK_EXTRAS_BUCKET])
36 # If successfully read bucket, then this must be a bot with permissions
37 return not rc
39 def main(args):
40 if is_android_buildbot_checkout():
41 success = True
42 for arg in args[1:]:
43 # Package is named <folder>_<package_name>_<version>
44 first_underscore = arg.find('_')
45 last_underscore = arg.rfind('_')
46 folder = arg[0:first_underscore]
47 package = arg[first_underscore+1:last_underscore]
48 # Package bucket is <SDK_EXTRAS_BUCKET>/<folder>_<package_name>_<version>
49 # and in that bucket will be the directory <folder>/<package_name> to cp.
50 package_bucket = '%s/%s/%s/%s' % (SDK_EXTRAS_BUCKET, arg, folder, package)
51 package_dir = '%s/%s/%s' % (SDK_EXTRAS_PATH, folder, package)
52 if not os.path.exists(package_dir):
53 os.makedirs(package_dir)
54 # rsync is only supported by gsutil version 4.x
55 cmd_lst = [GSUTIL_PATH, '--force-version', '4.6', '-m', 'rsync', '-r',
56 '-d', package_bucket, package_dir]
57 stdout, rc = GetCmdOutputAndStatus(cmd_lst)
58 success = (rc == 0) and success
59 if not success:
60 return 1
61 return 0
64 if __name__ == '__main__':
65 sys.exit(main(sys.argv))