OLD | NEW |
---|---|
(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 | |
14 if not sys.platform.startswith("linux"): | |
15 print "Not supported for your platform" | |
16 sys.exit(0) | |
17 | |
18 # Add //tools to the system path so that we can import the gs helper. | |
19 script_dir = os.path.dirname(os.path.realpath(__file__)) | |
20 tools_path = os.path.join(script_dir, os.pardir, os.pardir, "tools") | |
21 sys.path.insert(0, tools_path) | |
22 # pylint: disable=F0401 | |
23 import gs | |
24 | |
25 | |
26 def download_binary(version, platform, prebuilt_directory): | |
27 gs_path = "gs://mojo/network/%s/%s.zip" % (version, platform,) | |
jamesr
2015/01/23 23:15:00
why the ",)" ?
ppi
2015/01/23 23:24:35
Done.
| |
28 output_directory = os.path.join(prebuilt_directory, platform) | |
29 binary_name = "network_service.mojo" | |
30 | |
31 with tempfile.NamedTemporaryFile() as temp_zip_file: | |
32 gs.download_from_public_bucket(gs_path, temp_zip_file.name) | |
33 with zipfile.ZipFile(temp_zip_file.name) as z: | |
34 zi = z.getinfo(binary_name) | |
35 mode = zi.external_attr >> 16 | |
36 z.extract(zi, output_directory) | |
37 os.chmod(os.path.join(output_directory, binary_name), mode) | |
38 | |
39 | |
40 def main(): | |
41 parser = argparse.ArgumentParser( | |
42 description="Download prebuilt network service binaries from google " + | |
43 "storage") | |
44 parser.parse_args() | |
45 | |
46 prebuilt_directory_path = os.path.join(script_dir, "prebuilt") | |
47 stamp_path = os.path.join(prebuilt_directory_path, "STAMP") | |
48 | |
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 download_binary(version, platform, prebuilt_directory_path) | |
63 | |
64 with open(stamp_path, 'w') as stamp_file: | |
65 stamp_file.write(version) | |
66 return 0 | |
67 | |
68 | |
69 if __name__ == "__main__": | |
70 sys.exit(main()) | |
OLD | NEW |