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

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 os 7 import os
8 import sys 8 import sys
9 import tempfile 9 import tempfile
10 import zipfile 10 import zipfile
11 11
12 _PLATFORMS = ["linux-x64", "android-arm"] 12 _PLATFORMS = ["linux-x64", "android-arm"]
13 _APPS = ["network_service", "network_service_apptests"] 13 _APPS = ["network_service", "network_service_apptests"]
14 _CURRENT_PATH = os.path.dirname(os.path.realpath(__file__))
15 sys.path.insert(0, os.path.join(_CURRENT_PATH, "pylib"))
16 import gs
14 17
15 if not sys.platform.startswith("linux"): 18 if not sys.platform.startswith("linux"):
16 print "Not supported for your platform" 19 print "Not supported for your platform"
17 sys.exit(0) 20 sys.exit(0)
18 21
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__)) 22 script_dir = os.path.dirname(os.path.realpath(__file__))
21 23
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 24
29 25 def download_app(app, version, tools_directory):
30 def download_app(app, version):
31 prebuilt_directory = os.path.join(script_dir, "prebuilt/%s" % app) 26 prebuilt_directory = os.path.join(script_dir, "prebuilt/%s" % app)
32 stamp_path = os.path.join(prebuilt_directory, "VERSION") 27 stamp_path = os.path.join(prebuilt_directory, "VERSION")
33 28
34 try: 29 try:
35 with open(stamp_path) as stamp_file: 30 with open(stamp_path) as stamp_file:
36 current_version = stamp_file.read().strip() 31 current_version = stamp_file.read().strip()
37 if current_version == version: 32 if current_version == version:
38 return # Already have the right version. 33 return # Already have the right version.
39 except IOError: 34 except IOError:
40 pass # If the stamp file does not exist we need to download a new binary. 35 pass # If the stamp file does not exist we need to download a new binary.
41 36
42 for platform in _PLATFORMS: 37 for platform in _PLATFORMS:
43 download_app_for_platform(app, version, platform) 38 download_app_for_platform(app, version, platform, tools_directory)
44 39
45 with open(stamp_path, 'w') as stamp_file: 40 with open(stamp_path, 'w') as stamp_file:
46 stamp_file.write(version) 41 stamp_file.write(version)
47 42
48 def download_app_for_platform(app, version, platform): 43 def download_app_for_platform(app, version, platform, tools_directory):
44 find_depot_tools_path = os.path.join(_CURRENT_PATH, tools_directory)
49 binary_name = app + ".mojo" 45 binary_name = app + ".mojo"
50 gs_path = "gs://mojo/%s/%s/%s/%s.zip" % (app, version, platform, binary_name) 46 gs_path = "gs://mojo/%s/%s/%s/%s.zip" % (app, version, platform, binary_name)
51 output_directory = os.path.join(script_dir, 47 output_directory = os.path.join(script_dir,
52 "prebuilt/%s/%s" % (app, platform)) 48 "prebuilt/%s/%s" % (app, platform))
53 49
54 with tempfile.NamedTemporaryFile() as temp_zip_file: 50 with tempfile.NamedTemporaryFile() as temp_zip_file:
55 gs.download_from_public_bucket(gs_path, temp_zip_file.name) 51 gs.download_from_public_bucket(gs_path, temp_zip_file.name,
52 find_depot_tools_path)
56 with zipfile.ZipFile(temp_zip_file.name) as z: 53 with zipfile.ZipFile(temp_zip_file.name) as z:
57 zi = z.getinfo(binary_name) 54 zi = z.getinfo(binary_name)
58 mode = zi.external_attr >> 16 55 mode = zi.external_attr >> 16
59 z.extract(zi, output_directory) 56 z.extract(zi, output_directory)
60 os.chmod(os.path.join(output_directory, binary_name), mode) 57 os.chmod(os.path.join(output_directory, binary_name), mode)
61 58
62 def main(): 59 def main():
63 parser = argparse.ArgumentParser( 60 parser = argparse.ArgumentParser(
64 description="Download prebuilt network service binaries from google " + 61 description="Download prebuilt network service binaries from google " +
65 "storage") 62 "storage")
66 parser.parse_args() 63 parser.add_argument("--tools-directory",
64 dest="tools_directory",
65 metavar="<tools-directory>",
66 type=str,
67 required=True,
68 help="Path to the directory containing "
69 "find_depot_tools.py, specified as a relative path "
70 "from the location of this file.")
71 args = parser.parse_args()
67 72
68 version_path = os.path.join(script_dir, "NETWORK_SERVICE_VERSION") 73 version_path = os.path.join(script_dir, "NETWORK_SERVICE_VERSION")
69 with open(version_path) as version_file: 74 with open(version_path) as version_file:
70 version = version_file.read().strip() 75 version = version_file.read().strip()
71 76
72 for app in _APPS: 77 for app in _APPS:
73 download_app(app, version) 78 download_app(app, version, args.tools_directory)
74 79
75 return 0 80 return 0
76 81
77 82
78 if __name__ == "__main__": 83 if __name__ == "__main__":
79 sys.exit(main()) 84 sys.exit(main())
OLDNEW
« no previous file with comments | « DEPS ('k') | mojo/public/tools/download_shell_binary.py » ('j') | mojo/public/tools/pylib/gs.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698