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

Side by Side Diff: mojo/public/tools/download_network_service.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
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2015 The Chromium Authors. All rights reserved. 2 # Copyright 2015 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 gs
7 import os 8 import os
8 import sys 9 import sys
9 import tempfile 10 import tempfile
10 import zipfile 11 import zipfile
11 12
12 _PLATFORMS = ["linux-x64", "android-arm"] 13 _PLATFORMS = ["linux-x64", "android-arm"]
13 _APPS = ["network_service", "network_service_apptests"] 14 _APPS = ["network_service", "network_service_apptests"]
15 _CURRENT_PATH = os.path.dirname(os.path.realpath(__file__))
14 16
15 if not sys.platform.startswith("linux"): 17 if not sys.platform.startswith("linux"):
16 print "Not supported for your platform" 18 print "Not supported for your platform"
17 sys.exit(0) 19 sys.exit(0)
18 20
19 # Add //tools to the system path so that we can import the gs helper.
20 script_dir = os.path.dirname(os.path.realpath(__file__)) 21 script_dir = os.path.dirname(os.path.realpath(__file__))
21 22
22 # TODO(blundell): Determine whether to move gs.py into the SDK or to inline the
23 # contents of that function in this file as is done in download_shell_binary.py.
24 tools_path = os.path.join(script_dir, os.pardir, os.pardir, os.pardir, "tools")
25 sys.path.insert(0, tools_path)
26 # pylint: disable=F0401
27 import gs
28 23
29 24 def download_app(app, version, tools_directory):
30 def download_app(app, version):
31 prebuilt_directory = os.path.join(script_dir, "prebuilt/%s" % app) 25 prebuilt_directory = os.path.join(script_dir, "prebuilt/%s" % app)
32 stamp_path = os.path.join(prebuilt_directory, "VERSION") 26 stamp_path = os.path.join(prebuilt_directory, "VERSION")
33 27
34 try: 28 try:
35 with open(stamp_path) as stamp_file: 29 with open(stamp_path) as stamp_file:
36 current_version = stamp_file.read().strip() 30 current_version = stamp_file.read().strip()
37 if current_version == version: 31 if current_version == version:
38 return # Already have the right version. 32 return # Already have the right version.
39 except IOError: 33 except IOError:
40 pass # If the stamp file does not exist we need to download a new binary. 34 pass # If the stamp file does not exist we need to download a new binary.
41 35
42 for platform in _PLATFORMS: 36 for platform in _PLATFORMS:
43 download_app_for_platform(app, version, platform) 37 download_app_for_platform(app, version, platform, tools_directory)
44 38
45 with open(stamp_path, 'w') as stamp_file: 39 with open(stamp_path, 'w') as stamp_file:
46 stamp_file.write(version) 40 stamp_file.write(version)
47 41
48 def download_app_for_platform(app, version, platform): 42 def download_app_for_platform(app, version, platform, tools_directory):
43 find_depot_tools_path = os.path.join(_CURRENT_PATH, tools_directory)
49 binary_name = app + ".mojo" 44 binary_name = app + ".mojo"
50 gs_path = "gs://mojo/%s/%s/%s/%s.zip" % (app, version, platform, binary_name) 45 gs_path = "gs://mojo/%s/%s/%s/%s.zip" % (app, version, platform, binary_name)
51 output_directory = os.path.join(script_dir, 46 output_directory = os.path.join(script_dir,
52 "prebuilt/%s/%s" % (app, platform)) 47 "prebuilt/%s/%s" % (app, platform))
53 48
54 with tempfile.NamedTemporaryFile() as temp_zip_file: 49 with tempfile.NamedTemporaryFile() as temp_zip_file:
55 gs.download_from_public_bucket(gs_path, temp_zip_file.name) 50 gs.download_from_public_bucket(gs_path, temp_zip_file.name,
51 find_depot_tools_path)
56 with zipfile.ZipFile(temp_zip_file.name) as z: 52 with zipfile.ZipFile(temp_zip_file.name) as z:
57 zi = z.getinfo(binary_name) 53 zi = z.getinfo(binary_name)
58 mode = zi.external_attr >> 16 54 mode = zi.external_attr >> 16
59 z.extract(zi, output_directory) 55 z.extract(zi, output_directory)
60 os.chmod(os.path.join(output_directory, binary_name), mode) 56 os.chmod(os.path.join(output_directory, binary_name), mode)
61 57
62 def main(): 58 def main():
63 parser = argparse.ArgumentParser( 59 parser = argparse.ArgumentParser(
64 description="Download prebuilt network service binaries from google " + 60 description="Download prebuilt network service binaries from google " +
65 "storage") 61 "storage")
66 parser.parse_args() 62 parser.add_argument("--tools-directory",
63 dest="tools_directory",
64 metavar="<tools-directory>",
65 type=str,
66 help="Path to the directory containing"
67 " find_depot_tools.py, specified as a relative path"
viettrungluu 2015/02/11 23:54:49 <bikeshed>On a multiple-line concatenation of stri
blundell 2015/02/12 09:06:33 A quick-and-dirty non-scientific search indicates
68 " from the location of this file.")
69 args = parser.parse_args()
70 if not args.tools_directory:
71 print "Must specify --tools-directory; please see help message."
viettrungluu 2015/02/11 23:54:49 I believe you can just add required=True to add_ar
blundell 2015/02/12 09:06:33 Nice! Done.
72 sys.exit(1)
67 73
68 version_path = os.path.join(script_dir, "NETWORK_SERVICE_VERSION") 74 version_path = os.path.join(script_dir, "NETWORK_SERVICE_VERSION")
69 with open(version_path) as version_file: 75 with open(version_path) as version_file:
70 version = version_file.read().strip() 76 version = version_file.read().strip()
71 77
72 for app in _APPS: 78 for app in _APPS:
73 download_app(app, version) 79 download_app(app, version, args.tools_directory)
74 80
75 return 0 81 return 0
76 82
77 83
78 if __name__ == "__main__": 84 if __name__ == "__main__":
79 sys.exit(main()) 85 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698