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

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

Issue 910763002: Expose ability to download network service impl in SDK. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Fixes 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 = { 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 PREBUILT_FILE_PATH = os.path.join(CURRENT_PATH, "prebuilt") 23 PREBUILT_FILE_PATH = os.path.join(CURRENT_PATH, "prebuilt", "shell")
24 24
25 25
26 def download(tools_directory): 26 def download(tools_directory):
27 stamp_path = os.path.join(PREBUILT_FILE_PATH, "VERSION") 27 stamp_path = os.path.join(PREBUILT_FILE_PATH, "VERSION")
28 28
29 version_path = os.path.join(CURRENT_PATH, "../VERSION") 29 version_path = os.path.join(CURRENT_PATH, "../VERSION")
30 with open(version_path) as version_file: 30 with open(version_path) as version_file:
31 version = version_file.read().strip() 31 version = version_file.read().strip()
32 32
33 try: 33 try:
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 "cp", 76 "cp",
77 gs_path, 77 gs_path,
78 temp_zip_file.name], 78 temp_zip_file.name],
79 stderr=subprocess.STDOUT, 79 stderr=subprocess.STDOUT,
80 env=env) 80 env=env)
81 except subprocess.CalledProcessError as e: 81 except subprocess.CalledProcessError as e:
82 print e.output 82 print e.output
83 sys.exit(1) 83 sys.exit(1)
84 84
85 binary_name = BINARY_FOR_PLATFORM[platform] 85 binary_name = BINARY_FOR_PLATFORM[platform]
86 output_dir = os.path.join(PREBUILT_FILE_PATH, platform)
86 with zipfile.ZipFile(temp_zip_file.name) as z: 87 with zipfile.ZipFile(temp_zip_file.name) as z:
87 zi = z.getinfo(binary_name) 88 zi = z.getinfo(binary_name)
88 mode = zi.external_attr >> 16 89 mode = zi.external_attr >> 16
89 z.extract(zi, PREBUILT_FILE_PATH) 90 z.extract(zi, output_dir)
90 os.chmod(os.path.join(PREBUILT_FILE_PATH, binary_name), mode) 91 os.chmod(os.path.join(output_dir, binary_name), mode)
91 92
92 93
93 def main(): 94 def main():
94 parser = argparse.ArgumentParser(description="Download mojo_shell binaries " 95 parser = argparse.ArgumentParser(description="Download mojo_shell binaries "
95 "from google storage") 96 "from google storage")
96 parser.add_argument("--tools-directory", 97 parser.add_argument("--tools-directory",
97 dest="tools_directory", 98 dest="tools_directory",
98 metavar="<tools-directory>", 99 metavar="<tools-directory>",
99 type=str, 100 type=str,
100 help="Path to the directory containing" 101 help="Path to the directory containing"
101 " find_depot_tools.py, specified as a relative path" 102 " find_depot_tools.py, specified as a relative path"
102 " from the location of this file.") 103 " from the location of this file.")
103 args = parser.parse_args() 104 args = parser.parse_args()
104 if not args.tools_directory: 105 if not args.tools_directory:
105 print "Must specify --tools_directory; please see help message." 106 print "Must specify --tools_directory; please see help message."
106 sys.exit(1) 107 sys.exit(1)
107 return download(args.tools_directory) 108 return download(args.tools_directory)
108 109
109 if __name__ == "__main__": 110 if __name__ == "__main__":
110 sys.exit(main()) 111 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698