Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright (c) 2014 The Chromium Authors. All rights reserved. | |
|
nyquist
2014/12/19 16:19:17
Nit: Remove (c)
navabi
2014/12/19 19:14:28
Done.
| |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 """Script to download sdk/extras packages on the bots from google storage.""" | |
|
nyquist
2014/12/19 16:19:17
Could you add a short comment about the assumption
navabi
2014/12/19 19:14:28
Done.
| |
| 7 | |
| 8 import os | |
| 9 import subprocess | |
| 10 import sys | |
| 11 | |
| 12 sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'android')) | |
| 13 from pylib import constants | |
| 14 | |
| 15 GSUTIL_PATH = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, | |
| 16 os.pardir, os.pardir, os.pardir, os.pardir, 'depot_tools', 'gsutil.py') | |
| 17 SDK_EXTRAS_BUCKET = 'gs://chrome-sdk-extras' | |
| 18 SDK_EXTRAS_PATH = os.path.join(constants.ANDROID_SDK_ROOT, 'extras') | |
| 19 | |
| 20 | |
| 21 def GetCmdOutputAndStatus(cmd_lst): | |
| 22 process = subprocess.Popen(cmd_lst, stdout=subprocess.PIPE) | |
| 23 stdout, _ = process.communicate() | |
| 24 return stdout, process.returncode | |
| 25 | |
| 26 def is_buildbot_checkout(): | |
| 27 if not os.path.exists(GSUTIL_PATH) or not os.path.exists(SDK_EXTRAS_PATH): | |
| 28 return False | |
| 29 stdout, rc = GetCmdOutputAndStatus([GSUTIL_PATH, 'ls', SDK_EXTRAS_BUCKET]) | |
| 30 # If successfully read bucket, then this must be a bot with permissions | |
| 31 return not rc | |
| 32 | |
| 33 def main(args): | |
| 34 if is_buildbot_checkout(): | |
| 35 success = True | |
| 36 for arg in args[1:]: | |
| 37 # Package is named <folder>_<package_name>_<version> | |
| 38 first_underscore = arg.find('_') | |
| 39 last_underscore = arg.rfind('_') | |
| 40 folder = arg[0:first_underscore] | |
| 41 package = arg[first_underscore+1:last_underscore] | |
| 42 package_bucket = '%s/%s/%s/%s' % (SDK_EXTRAS_BUCKET, arg, folder, package) | |
|
nyquist
2014/12/19 16:19:17
Could you add an example comment for package_bucke
navabi
2014/12/19 19:14:28
Done.
| |
| 43 package_dir = '%s/%s/%s' % (SDK_EXTRAS_PATH, folder, package) | |
| 44 if not os.path.exists(package_dir): | |
| 45 os.makedirs(package_dir) | |
| 46 # rsync is only supported by gsutil version 4.x | |
| 47 cmd_lst = [GSUTIL_PATH, '--force-version', '4.6', '-m', 'rsync', '-r', | |
| 48 '-d', package_bucket, package_dir] | |
| 49 stdout, rc = GetCmdOutputAndStatus(cmd_lst) | |
| 50 success = (rc == 0) and success | |
| 51 if not success: | |
| 52 return 1 | |
| 53 return 0 | |
| 54 | |
| 55 | |
| 56 if __name__ == '__main__': | |
| 57 sys.exit(main(sys.argv)) | |
| OLD | NEW |