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 an argument that specifies the packet name in the following | 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 | 9 format: <dir_in_sdk_extras>_<package_name>_<version>. There will be a |
cjhopman
2014/12/31 00:39:29
The expected argument is slightly different now
navabi
2015/01/06 00:32:09
Done.
| |
10 correpsonding bucket in google storage with that name, and it will be downloaded | 10 correpsonding bucket in google storage with that name, and it will be downloaded |
11 to android_tools/sdk/extras/. | 11 to android_tools/sdk/extras/. |
12 """ | 12 """ |
13 | 13 |
14 import os | 14 import os |
15 import subprocess | 15 import subprocess |
16 import sys | 16 import sys |
17 | 17 |
18 sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'android')) | 18 sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'android')) |
19 from pylib import constants | 19 from pylib import constants |
20 | 20 |
21 GSUTIL_PATH = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, | 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') | 22 os.pardir, os.pardir, os.pardir, os.pardir, 'depot_tools', 'gsutil.py') |
23 SDK_EXTRAS_BUCKET = 'gs://chrome-sdk-extras' | 23 SDK_EXTRAS_BUCKET = 'gs://chrome-sdk-extras' |
24 SDK_EXTRAS_PATH = os.path.join(constants.ANDROID_SDK_ROOT, 'extras') | 24 SDK_EXTRAS_PATH = os.path.join(constants.ANDROID_SDK_ROOT, 'extras') |
25 | 25 |
26 | 26 |
27 def GetCmdOutputAndStatus(cmd_lst): | 27 def GetCmdOutputAndStatus(cmd_lst): |
28 process = subprocess.Popen(cmd_lst, stdout=subprocess.PIPE) | 28 process = subprocess.Popen(cmd_lst, stdout=subprocess.PIPE) |
29 stdout, _ = process.communicate() | 29 stdout, _ = process.communicate() |
30 return stdout, process.returncode | 30 return stdout, process.returncode |
31 | 31 |
32 def is_android_buildbot_checkout(): | 32 def is_android_buildbot_checkout(): |
33 if not os.path.exists(GSUTIL_PATH) or not os.path.exists(SDK_EXTRAS_PATH): | 33 if not os.path.exists(GSUTIL_PATH) or not os.path.exists(SDK_EXTRAS_PATH): |
34 return False | 34 return False |
35 stdout, rc = GetCmdOutputAndStatus([GSUTIL_PATH, 'ls', SDK_EXTRAS_BUCKET]) | 35 _, rc = GetCmdOutputAndStatus([GSUTIL_PATH, 'ls', SDK_EXTRAS_BUCKET]) |
36 # If successfully read bucket, then this must be a bot with permissions | 36 # If successfully read bucket, then this must be a bot with permissions |
hinoka
2014/12/31 00:32:55
Not always. Sometimes its possible to download a
navabi
2014/12/31 00:37:59
Acknowledged. I'll fix this.
| |
37 return not rc | 37 return not rc |
38 | 38 |
39 def main(args): | 39 def main(args): |
40 if is_android_buildbot_checkout(): | 40 if is_android_buildbot_checkout(): |
41 success = True | 41 success = True |
42 for arg in args[1:]: | 42 for arg in args[1:]: |
43 # Package is named <folder>_<package_name>_<version> | 43 # Package zip is named <folder>_<package_name>_<version>.zip. Unzipping |
hinoka
2014/12/31 00:32:55
We shouldn't re-download the zip if we have all th
navabi
2014/12/31 00:37:59
How do we check if the files contain the same cont
cjhopman
2014/12/31 00:41:50
Can we assume that the version number actually wor
nyquist
2014/12/31 00:42:43
How about using 'gsutil hash' or 'gsutil stat' lik
| |
44 first_underscore = arg.find('_') | 44 # will create dir <SDK_EXTRAS_BUCKET>/<folder>/<package_name>/*. |
45 last_underscore = arg.rfind('_') | 45 package_zip = '%s/%s' % (SDK_EXTRAS_BUCKET, arg) |
46 folder = arg[0:first_underscore] | 46 local_path = '%s/' % SDK_EXTRAS_PATH |
cjhopman
2014/12/31 00:41:50
Could there be stuff in local_path from previous r
| |
47 package = arg[first_underscore+1:last_underscore] | 47 cmd_lst = [GSUTIL_PATH, 'cp', package_zip, local_path] |
48 # Package bucket is <SDK_EXTRAS_BUCKET>/<folder>_<package_name>_<version> | 48 _, rc = GetCmdOutputAndStatus(cmd_lst) |
cjhopman
2014/12/31 00:39:29
How about:
subprocess.check_output(cmd_lst)
or,
| |
49 # and in that bucket will be the directory <folder>/<package_name> to cp. | 49 if not rc: |
50 package_bucket = '%s/%s/%s/%s' % (SDK_EXTRAS_BUCKET, arg, folder, package) | 50 zip_file = '%s/%s' % (SDK_EXTRAS_PATH, arg) |
51 package_dir = '%s/%s/%s' % (SDK_EXTRAS_PATH, folder, package) | 51 cmd_lst = ['unzip', '-u', zip_file, '-d', local_path] |
52 if not os.path.exists(package_dir): | 52 _, rc = GetCmdOutputAndStatus(cmd_lst) |
53 os.makedirs(package_dir) | 53 success = (rc == 0) and success |
54 # rsync is only supported by gsutil version 4.x | 54 else: |
55 cmd_lst = [GSUTIL_PATH, '--force-version', '4.6', '-m', 'rsync', '-r', | 55 success = False |
56 '-d', package_bucket, package_dir] | |
57 stdout, rc = GetCmdOutputAndStatus(cmd_lst) | |
58 success = (rc == 0) and success | |
59 if not success: | 56 if not success: |
60 return 1 | 57 return 1 |
61 return 0 | 58 return 0 |
62 | 59 |
63 | 60 |
64 if __name__ == '__main__': | 61 if __name__ == '__main__': |
65 sys.exit(main(sys.argv)) | 62 sys.exit(main(sys.argv)) |
OLD | NEW |