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

Side by Side Diff: mojo/services/network/download_network_service.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
(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
15 if not sys.platform.startswith("linux"):
16 print "Not supported for your platform"
17 sys.exit(0)
18
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 tools_path = os.path.join(script_dir, os.pardir, os.pardir, os.pardir, "tools")
22 sys.path.insert(0, tools_path)
23 # pylint: disable=F0401
24 import gs
25
26
27 def download_app(app, version, platform, prebuilt_directory):
28 binary_name = app + ".mojo"
29 gs_path = "gs://mojo/%s/%s/%s/%s.zip" % (app, version, platform, binary_name)
30 output_directory = os.path.join(prebuilt_directory, platform)
31
32 with tempfile.NamedTemporaryFile() as temp_zip_file:
33 gs.download_from_public_bucket(gs_path, temp_zip_file.name)
34 with zipfile.ZipFile(temp_zip_file.name) as z:
35 zi = z.getinfo(binary_name)
36 mode = zi.external_attr >> 16
37 z.extract(zi, output_directory)
38 os.chmod(os.path.join(output_directory, binary_name), mode)
39
40
41 def main():
42 parser = argparse.ArgumentParser(
43 description="Download prebuilt network service binaries from google " +
44 "storage")
45 parser.parse_args()
46
47 prebuilt_directory_path = os.path.join(script_dir, "prebuilt")
48 stamp_path = os.path.join(prebuilt_directory_path, "STAMP")
49 version_path = os.path.join(script_dir, "VERSION")
50 with open(version_path) as version_file:
51 version = version_file.read().strip()
52
53 try:
54 with open(stamp_path) as stamp_file:
55 current_version = stamp_file.read().strip()
56 if current_version == version:
57 return 0 # Already have the right version.
58 except IOError:
59 pass # If the stamp file does not exist we need to download a new binary.
60
61 for platform in _PLATFORMS:
62 for app in _APPS:
63 download_app(app, version, platform, prebuilt_directory_path)
64
65 with open(stamp_path, 'w') as stamp_file:
66 stamp_file.write(version)
67 return 0
68
69
70 if __name__ == "__main__":
71 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698