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) |
| 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 version_path = os.path.join(script_dir, "VERSION") |
| 49 with open(version_path) as version_file: |
| 50 version = version_file.read().strip() |
| 51 |
| 52 try: |
| 53 with open(stamp_path) as stamp_file: |
| 54 current_version = stamp_file.read().strip() |
| 55 if current_version == version: |
| 56 return 0 # Already have the right version. |
| 57 except IOError: |
| 58 pass # If the stamp file does not exist we need to download a new binary. |
| 59 |
| 60 for platform in _PLATFORMS: |
| 61 download_binary(version, platform, prebuilt_directory_path) |
| 62 |
| 63 with open(stamp_path, 'w') as stamp_file: |
| 64 stamp_file.write(version) |
| 65 return 0 |
| 66 |
| 67 |
| 68 if __name__ == "__main__": |
| 69 sys.exit(main()) |
OLD | NEW |