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

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

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

Powered by Google App Engine
This is Rietveld 408576698