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

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

Issue 870143008: Move //tools/gs.py into //mojo/public/tools (Closed) Base URL: https://github.com/domokit/mojo.git@expose_downloading_network_service
Patch Set: Response to review 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
« no previous file with comments | « mojo/public/tools/download_network_service.py ('k') | mojo/public/tools/pylib/gs.py » ('j') | 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 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 = { 13 BINARY_FOR_PLATFORM = {
14 "linux-x64" : "mojo_shell", 14 "linux-x64" : "mojo_shell",
15 "android-arm" : "MojoShell.apk" 15 "android-arm" : "MojoShell.apk"
16 } 16 }
17 17
18 if not sys.platform.startswith("linux"): 18 if not sys.platform.startswith("linux"):
19 print "Not supported for your platform" 19 print "Not supported for your platform"
20 sys.exit(0) 20 sys.exit(0)
21 21
22 CURRENT_PATH = os.path.dirname(os.path.realpath(__file__)) 22 CURRENT_PATH = os.path.dirname(os.path.realpath(__file__))
23 sys.path.insert(0, os.path.join(CURRENT_PATH, "pylib"))
24 import gs
25
23 PREBUILT_FILE_PATH = os.path.join(CURRENT_PATH, "prebuilt", "shell") 26 PREBUILT_FILE_PATH = os.path.join(CURRENT_PATH, "prebuilt", "shell")
24 27
25 28
26 def download(tools_directory): 29 def download(tools_directory):
27 stamp_path = os.path.join(PREBUILT_FILE_PATH, "VERSION") 30 stamp_path = os.path.join(PREBUILT_FILE_PATH, "VERSION")
28 31
29 version_path = os.path.join(CURRENT_PATH, "../VERSION") 32 version_path = os.path.join(CURRENT_PATH, "../VERSION")
30 with open(version_path) as version_file: 33 with open(version_path) as version_file:
31 version = version_file.read().strip() 34 version = version_file.read().strip()
32 35
(...skipping 10 matching lines...) Expand all
43 46
44 with open(stamp_path, 'w') as stamp_file: 47 with open(stamp_path, 'w') as stamp_file:
45 stamp_file.write(version) 48 stamp_file.write(version)
46 return 0 49 return 0
47 50
48 def download_version_for_platform(version, platform, tools_directory): 51 def download_version_for_platform(version, platform, tools_directory):
49 find_depot_tools_path = os.path.join(CURRENT_PATH, tools_directory) 52 find_depot_tools_path = os.path.join(CURRENT_PATH, tools_directory)
50 sys.path.insert(0, find_depot_tools_path) 53 sys.path.insert(0, find_depot_tools_path)
51 # pylint: disable=F0401 54 # pylint: disable=F0401
52 import find_depot_tools 55 import find_depot_tools
56 depot_tools_path = find_depot_tools.add_depot_tools_to_path()
53 57
54 basename = platform + ".zip" 58 basename = platform + ".zip"
55 gs_path = "gs://mojo/shell/" + version + "/" + basename 59 gs_path = "gs://mojo/shell/" + version + "/" + basename
56 60
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: 61 with tempfile.NamedTemporaryFile() as temp_zip_file:
61 # We're downloading from a public bucket which does not need authentication, 62 gs.download_from_public_bucket(gs_path, temp_zip_file.name,
62 # but the user might have busted credential files somewhere such as ~/.boto 63 depot_tools_path)
63 # that the gsutil script will try (and fail) to use. Setting these
64 # 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
66 # 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
68 # throw the output away if the script succeeds (return code 0).
69 env = os.environ.copy()
70 env["AWS_CREDENTIAL_FILE"] = ""
71 env["BOTO_CONFIG"] = ""
72 try:
73 subprocess.check_output(
74 [gsutil_exe,
75 "--bypass_prodaccess",
76 "cp",
77 gs_path,
78 temp_zip_file.name],
79 stderr=subprocess.STDOUT,
80 env=env)
81 except subprocess.CalledProcessError as e:
82 print e.output
83 sys.exit(1)
84
85 binary_name = BINARY_FOR_PLATFORM[platform] 64 binary_name = BINARY_FOR_PLATFORM[platform]
86 output_dir = os.path.join(PREBUILT_FILE_PATH, platform) 65 output_dir = os.path.join(PREBUILT_FILE_PATH, platform)
87 with zipfile.ZipFile(temp_zip_file.name) as z: 66 with zipfile.ZipFile(temp_zip_file.name) as z:
88 zi = z.getinfo(binary_name) 67 zi = z.getinfo(binary_name)
89 mode = zi.external_attr >> 16 68 mode = zi.external_attr >> 16
90 z.extract(zi, output_dir) 69 z.extract(zi, output_dir)
91 os.chmod(os.path.join(output_dir, binary_name), mode) 70 os.chmod(os.path.join(output_dir, binary_name), mode)
92 71
93 72
94 def main(): 73 def main():
95 parser = argparse.ArgumentParser(description="Download mojo_shell binaries " 74 parser = argparse.ArgumentParser(description="Download mojo_shell binaries "
96 "from google storage") 75 "from google storage")
97 parser.add_argument("--tools-directory", 76 parser.add_argument("--tools-directory",
98 dest="tools_directory", 77 dest="tools_directory",
99 metavar="<tools-directory>", 78 metavar="<tools-directory>",
100 type=str, 79 type=str,
101 help="Path to the directory containing" 80 required=True,
102 " find_depot_tools.py, specified as a relative path" 81 help="Path to the directory containing "
103 " from the location of this file.") 82 "find_depot_tools.py, specified as a relative path "
83 "from the location of this file.")
104 args = parser.parse_args() 84 args = parser.parse_args()
105 if not args.tools_directory:
106 print "Must specify --tools_directory; please see help message."
107 sys.exit(1)
108 return download(args.tools_directory) 85 return download(args.tools_directory)
109 86
110 if __name__ == "__main__": 87 if __name__ == "__main__":
111 sys.exit(main()) 88 sys.exit(main())
OLDNEW
« no previous file with comments | « mojo/public/tools/download_network_service.py ('k') | mojo/public/tools/pylib/gs.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698