Index: build/download_sdk_extras.py |
diff --git a/build/download_sdk_extras.py b/build/download_sdk_extras.py |
index 1149d9d29641a7814b6271bb53c76acdabc69db5..ca307751f62afd788640719ec8961c1c0e000c72 100755 |
--- a/build/download_sdk_extras.py |
+++ b/build/download_sdk_extras.py |
@@ -5,15 +5,16 @@ |
"""Script to download sdk/extras packages on the bots from google storage. |
-The script expects an argument that specifies the packet name in the following |
-format: <dir_in_sdk_extras>_<package_name>_<version>. There will be a |
-correpsonding bucket in google storage with that name, and it will be downloaded |
-to android_tools/sdk/extras/. |
+The script expects arguments that specify zips file in the google storage |
+bucket named: <dir in SDK extras>_<package name>_<version>.zip. The file will |
+be extracted in the android_tools/sdk/extras directory. |
""" |
import os |
+import shutil |
import subprocess |
import sys |
+import zipfile |
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'android')) |
from pylib import constants |
@@ -24,41 +25,31 @@ SDK_EXTRAS_BUCKET = 'gs://chrome-sdk-extras' |
SDK_EXTRAS_PATH = os.path.join(constants.ANDROID_SDK_ROOT, 'extras') |
-def GetCmdOutputAndStatus(cmd_lst): |
- process = subprocess.Popen(cmd_lst, stdout=subprocess.PIPE) |
- stdout, _ = process.communicate() |
- return stdout, process.returncode |
+def clean_and_extract(zip_file): |
+ # Extract the directory name and package name from zip file name. The format |
+ # of the zip file is <dir in sdk/extras>_<package_name>_<version>.zip. |
+ dir_name = zip_file[:zip_file.index('_')] |
+ package_name = zip_file[zip_file.index('_')+1:zip_file.rindex('_')] |
+ local_dir = '%s/%s/%s' % (SDK_EXTRAS_PATH, dir_name, package_name) |
+ if os.path.exists(local_dir): |
+ shutil.rmtree(local_dir) |
+ local_zip = '%s/%s' % (SDK_EXTRAS_PATH, zip_file) |
+ with zipfile.ZipFile(local_zip) as z: |
+ z.extractall(path=SDK_EXTRAS_PATH) |
-def is_android_buildbot_checkout(): |
- if not os.path.exists(GSUTIL_PATH) or not os.path.exists(SDK_EXTRAS_PATH): |
- return False |
- stdout, rc = GetCmdOutputAndStatus([GSUTIL_PATH, 'ls', SDK_EXTRAS_BUCKET]) |
- # If successfully read bucket, then this must be a bot with permissions |
- return not rc |
def main(args): |
- if is_android_buildbot_checkout(): |
- success = True |
- for arg in args[1:]: |
- # Package is named <folder>_<package_name>_<version> |
- first_underscore = arg.find('_') |
- last_underscore = arg.rfind('_') |
- folder = arg[0:first_underscore] |
- package = arg[first_underscore+1:last_underscore] |
- # Package bucket is <SDK_EXTRAS_BUCKET>/<folder>_<package_name>_<version> |
- # and in that bucket will be the directory <folder>/<package_name> to cp. |
- package_bucket = '%s/%s/%s/%s' % (SDK_EXTRAS_BUCKET, arg, folder, package) |
- package_dir = '%s/%s/%s' % (SDK_EXTRAS_PATH, folder, package) |
- if not os.path.exists(package_dir): |
- os.makedirs(package_dir) |
- # rsync is only supported by gsutil version 4.x |
- cmd_lst = [GSUTIL_PATH, '--force-version', '4.6', '-m', 'rsync', '-r', |
- '-d', package_bucket, package_dir] |
- stdout, rc = GetCmdOutputAndStatus(cmd_lst) |
- success = (rc == 0) and success |
- if not success: |
- return 1 |
- return 0 |
+ if not os.path.exists(GSUTIL_PATH) or not os.path.exists(SDK_EXTRAS_PATH): |
+ # This is not a buildbot checkout. |
kjellander_chromium
2015/01/28 11:05:09
This is a really bad assumption to make. There are
|
+ return 0 |
+ for arg in args[1:]: |
+ local_zip = '%s/%s' % (SDK_EXTRAS_PATH, arg) |
+ if not os.path.exists(local_zip): |
+ package_zip = '%s/%s' % (SDK_EXTRAS_BUCKET, arg) |
+ subprocess.check_call([GSUTIL_PATH, '--force-version', '4.7', 'cp', |
+ package_zip, local_zip]) |
+ # Always clean dir and extract zip to ensure correct contents. |
+ clean_and_extract(arg) |
if __name__ == '__main__': |