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

Side by Side Diff: third_party/mojo/src/mojo/public/tools/download_shell_binary.py

Issue 890843003: Revert of Update mojo sdk to rev 8af2ccff2eee4bfca1043015abee30482a030b30 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
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 import argparse 6 import argparse
7 import os 7 import os
8 import subprocess 8 import subprocess
9 import sys 9 import sys
10 import tempfile 10 import tempfile
11 import zipfile 11 import zipfile
12 12
13 BINARY_FOR_PLATFORM = {
14 "linux-x64" : "mojo_shell",
15 "android-arm" : "MojoShell.apk"
16 }
17
18 if not sys.platform.startswith("linux"): 13 if not sys.platform.startswith("linux"):
19 print "Not supported for your platform" 14 print "Not supported for your platform"
20 sys.exit(0) 15 sys.exit(0)
21 16
22 CURRENT_PATH = os.path.dirname(os.path.realpath(__file__))
23 PREBUILT_FILE_PATH = os.path.join(CURRENT_PATH, "prebuilt")
24
25 17
26 def download(tools_directory): 18 def download(tools_directory):
27 stamp_path = os.path.join(PREBUILT_FILE_PATH, "VERSION") 19 current_path = os.path.dirname(os.path.realpath(__file__))
20 find_depot_tools_path = os.path.join(current_path, tools_directory)
21 sys.path.insert(0, find_depot_tools_path)
22 # pylint: disable=F0401
23 import find_depot_tools
28 24
29 version_path = os.path.join(CURRENT_PATH, "../VERSION") 25 prebuilt_file_path = os.path.join(current_path, "prebuilt")
26 stamp_path = os.path.join(prebuilt_file_path, "VERSION")
27
28 depot_tools_path = find_depot_tools.add_depot_tools_to_path()
29 gsutil_exe = os.path.join(depot_tools_path, "third_party", "gsutil", "gsutil")
30
31 version_path = os.path.join(current_path, "../VERSION")
30 with open(version_path) as version_file: 32 with open(version_path) as version_file:
31 version = version_file.read().strip() 33 version = version_file.read().strip()
32 34
33 try: 35 try:
34 with open(stamp_path) as stamp_file: 36 with open(stamp_path) as stamp_file:
35 current_version = stamp_file.read().strip() 37 current_version = stamp_file.read().strip()
36 if current_version == version: 38 if current_version == version:
37 return 0 # Already have the right version. 39 return 0 # Already have the right version.
38 except IOError: 40 except IOError:
39 pass # If the stamp file does not exist we need to download new binaries. 41 pass # If the stamp file does not exist we need to download a new binary.
40 42
41 for platform in ["linux-x64", "android-arm"]: 43 platform = "linux-x64" # TODO: configurate
42 download_version_for_platform(version, platform, tools_directory) 44 basename = platform + ".zip"
43 45
44 with open(stamp_path, 'w') as stamp_file:
45 stamp_file.write(version)
46 return 0
47
48 def download_version_for_platform(version, platform, tools_directory):
49 find_depot_tools_path = os.path.join(CURRENT_PATH, tools_directory)
50 sys.path.insert(0, find_depot_tools_path)
51 # pylint: disable=F0401
52 import find_depot_tools
53
54 basename = platform + ".zip"
55 gs_path = "gs://mojo/shell/" + version + "/" + basename 46 gs_path = "gs://mojo/shell/" + version + "/" + basename
56 47
57 depot_tools_path = find_depot_tools.add_depot_tools_to_path()
58 gsutil_exe = os.path.join(depot_tools_path, "third_party", "gsutil", "gsutil")
59
60 with tempfile.NamedTemporaryFile() as temp_zip_file: 48 with tempfile.NamedTemporaryFile() as temp_zip_file:
61 # We're downloading from a public bucket which does not need authentication, 49 # We're downloading from a public bucket which does not need authentication,
62 # but the user might have busted credential files somewhere such as ~/.boto 50 # but the user might have busted credential files somewhere such as ~/.boto
63 # that the gsutil script will try (and fail) to use. Setting these 51 # that the gsutil script will try (and fail) to use. Setting these
64 # environment variables convinces gsutil not to attempt to use these, but 52 # environment variables convinces gsutil not to attempt to use these, but
65 # also generates a useless warning about failing to load the file. We want 53 # also generates a useless warning about failing to load the file. We want
66 # to discard this warning but still preserve all output in the case of an 54 # to discard this warning but still preserve all output in the case of an
67 # actual failure. So, we run the script and capture all output and then 55 # actual failure. So, we run the script and capture all output and then
68 # throw the output away if the script succeeds (return code 0). 56 # throw the output away if the script succeeds (return code 0).
69 env = os.environ.copy() 57 env = os.environ.copy()
70 env["AWS_CREDENTIAL_FILE"] = "" 58 env["AWS_CREDENTIAL_FILE"] = ""
71 env["BOTO_CONFIG"] = "" 59 env["BOTO_CONFIG"] = ""
72 try: 60 try:
73 subprocess.check_output( 61 subprocess.check_output(
74 [gsutil_exe, 62 [gsutil_exe,
75 "--bypass_prodaccess", 63 "--bypass_prodaccess",
76 "cp", 64 "cp",
77 gs_path, 65 gs_path,
78 temp_zip_file.name], 66 temp_zip_file.name],
79 stderr=subprocess.STDOUT, 67 stderr=subprocess.STDOUT,
80 env=env) 68 env=env)
81 except subprocess.CalledProcessError as e: 69 except subprocess.CalledProcessError as e:
82 print e.output 70 print e.output
83 sys.exit(1) 71 sys.exit(1)
84 72
85 binary_name = BINARY_FOR_PLATFORM[platform]
86 with zipfile.ZipFile(temp_zip_file.name) as z: 73 with zipfile.ZipFile(temp_zip_file.name) as z:
87 zi = z.getinfo(binary_name) 74 zi = z.getinfo("mojo_shell")
88 mode = zi.external_attr >> 16 75 mode = zi.external_attr >> 16
89 z.extract(zi, PREBUILT_FILE_PATH) 76 z.extract(zi, prebuilt_file_path)
90 os.chmod(os.path.join(PREBUILT_FILE_PATH, binary_name), mode) 77 os.chmod(os.path.join(prebuilt_file_path, "mojo_shell"), mode)
78
79 with open(stamp_path, 'w') as stamp_file:
80 stamp_file.write(version)
81 return 0
91 82
92 83
93 def main(): 84 def main():
94 parser = argparse.ArgumentParser(description="Download mojo_shell binaries " 85 parser = argparse.ArgumentParser(description="Download mojo_shell binary "
95 "from google storage") 86 "from google storage")
96 parser.add_argument("--tools-directory", 87 parser.add_argument("--tools-directory",
97 dest="tools_directory", 88 dest="tools_directory",
98 metavar="<tools-directory>", 89 metavar="<tools-directory>",
99 type=str, 90 type=str,
100 help="Path to the directory containing" 91 help="Path to the directory containing"
101 " find_depot_tools.py, specified as a relative path" 92 " find_depot_tools.py, specified as a relative path"
102 " from the location of this file.") 93 " from the location of this file.")
103 args = parser.parse_args() 94 args = parser.parse_args()
104 if not args.tools_directory: 95 if not args.tools_directory:
105 print "Must specify --tools_directory; please see help message." 96 print "Must specify --tools_directory; please see help message."
106 sys.exit(1) 97 sys.exit(1)
107 return download(args.tools_directory) 98 return download(args.tools_directory)
108 99
109 if __name__ == "__main__": 100 if __name__ == "__main__":
110 sys.exit(main()) 101 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698