Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(463)

Side by Side Diff: build/download_sdk_extras.py

Issue 799673003: Always download google_play_services zip package instead of rsync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add clean to remove existing package. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « DEPS ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 an argument that specifies the packet name in the following 8 The script expects arguments that specify zips file in the google storage
9 format: <dir_in_sdk_extras>_<package_name>_<version>. There will be a 9 bucket named: <dir in SDK extras>_<package name>_<version>.zip. The file will
10 correpsonding bucket in google storage with that name, and it will be downloaded 10 be extracted in the android_tools/sdk/extras directory.
11 to android_tools/sdk/extras/.
12 """ 11 """
13 12
14 import os 13 import os
15 import subprocess 14 import subprocess
16 import sys 15 import sys
17 16
18 sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'android')) 17 sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'android'))
19 from pylib import constants 18 from pylib import constants
20 19
21 GSUTIL_PATH = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, 20 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') 21 os.pardir, os.pardir, os.pardir, os.pardir, 'depot_tools', 'gsutil.py')
23 SDK_EXTRAS_BUCKET = 'gs://chrome-sdk-extras' 22 SDK_EXTRAS_BUCKET = 'gs://chrome-sdk-extras'
24 SDK_EXTRAS_PATH = os.path.join(constants.ANDROID_SDK_ROOT, 'extras') 23 SDK_EXTRAS_PATH = os.path.join(constants.ANDROID_SDK_ROOT, 'extras')
25 24
26 25
27 def GetCmdOutputAndStatus(cmd_lst): 26 def clean_and_extract(zip_file):
28 process = subprocess.Popen(cmd_lst, stdout=subprocess.PIPE) 27 # Extract the directory name and package name from zip file name. The format
29 stdout, _ = process.communicate() 28 # of the zip file is <dir in sdk/extras>_<package_name>_<version>.zip.
30 return stdout, process.returncode 29 dir_name = zip_file[:zip_file.index('_')]
30 package_name = zip_file[zip_file.index('_')+1:zip_file.rindex('_')]
31 local_dir = '%s/%s/%s' % (SDK_EXTRAS_PATH, dir_name, package_name)
32 cmd_lst = ['rm', '-rf', local_dir]
cjhopman 2015/01/06 02:04:04 instead of subbing out to 'rm -rf', you can do: i
navabi 2015/01/06 19:10:13 Done.
33 rc = subprocess.check_call(cmd_lst)
cjhopman 2015/01/06 02:04:04 check_call throws an exception if the returncode i
navabi 2015/01/06 19:10:13 Acknowledged.
34 if rc:
35 return rc
36 local_zip = '%s/%s' % (SDK_EXTRAS_PATH, zip_file)
37 cmd_lst = ['unzip', '-u', local_zip, '-d', SDK_EXTRAS_PATH]
cjhopman 2015/01/06 02:04:04 You could use python's zipfile here something lik
navabi 2015/01/06 19:10:13 Done.
38 return subprocess.check_call(cmd_lst)
31 39
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
38 40
39 def main(args): 41 def main(args):
40 if is_android_buildbot_checkout(): 42 if not os.path.exists(GSUTIL_PATH) or not os.path.exists(SDK_EXTRAS_PATH):
41 success = True 43 # This is not a buildbot checkout.
42 for arg in args[1:]: 44 return 0
43 # Package is named <folder>_<package_name>_<version> 45 success = True
44 first_underscore = arg.find('_') 46 for arg in args[1:]:
45 last_underscore = arg.rfind('_') 47 local_zip = '%s/%s' % (SDK_EXTRAS_PATH, arg)
46 folder = arg[0:first_underscore] 48 if os.path.exists(local_zip):
cjhopman 2015/01/06 02:04:04 this if/else can just be: if not os.path.exists(l
navabi 2015/01/06 19:10:13 Done. (and there is really no point in doing the s
47 package = arg[first_underscore+1:last_underscore] 49 # Always clean dir and extract zip to ensure correct contents.
48 # Package bucket is <SDK_EXTRAS_BUCKET>/<folder>_<package_name>_<version> 50 clean_and_extract(arg)
49 # and in that bucket will be the directory <folder>/<package_name> to cp. 51 else:
50 package_bucket = '%s/%s/%s/%s' % (SDK_EXTRAS_BUCKET, arg, folder, package) 52 # Package zip is named <folder>_<package_name>_<version>.zip.
51 package_dir = '%s/%s/%s' % (SDK_EXTRAS_PATH, folder, package) 53 package_zip = '%s/%s' % (SDK_EXTRAS_BUCKET, arg)
52 if not os.path.exists(package_dir): 54 rc = subprocess.check_call([GSUTIL_PATH, '--force-version', '4.7', 'stat',
53 os.makedirs(package_dir) 55 package_zip])
54 # rsync is only supported by gsutil version 4.x 56 if rc:
55 cmd_lst = [GSUTIL_PATH, '--force-version', '4.6', '-m', 'rsync', '-r', 57 return 1
56 '-d', package_bucket, package_dir] 58 rc = subprocess.check_call([GSUTIL_PATH, '--force-version', '4.7', 'cp',
57 stdout, rc = GetCmdOutputAndStatus(cmd_lst) 59 package_zip, local_zip])
58 success = (rc == 0) and success 60 if not rc:
59 if not success: 61 rc = clean_and_extract(arg)
60 return 1 62 success = (rc == 0) and success
61 return 0 63 else:
64 success = False
65 if not success:
66 return 1
62 67
63 68
64 if __name__ == '__main__': 69 if __name__ == '__main__':
65 sys.exit(main(sys.argv)) 70 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « DEPS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698