Explicitly add python-numpy dependency to install-build-deps.
[chromium-blink-merge.git] / mojo / public / tools / download_shell_binary.py
blobe28034c0fe75478475a3a6f32180bc5984378f9e
1 #!/usr/bin/env python
2 # Copyright 2014 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.
6 import argparse
7 import os
8 import subprocess
9 import sys
10 import tempfile
11 import zipfile
13 current_path = os.path.dirname(os.path.realpath(__file__))
14 sys.path.insert(0, os.path.join(current_path, "..", "..", "..", "tools"))
15 # pylint: disable=F0401
16 import find_depot_tools
18 if not sys.platform.startswith("linux"):
19 print "Not supported for your platform"
20 sys.exit(0)
22 prebuilt_file_path = os.path.join(current_path, "prebuilt")
23 stamp_path = os.path.join(prebuilt_file_path, "VERSION")
25 depot_tools_path = find_depot_tools.add_depot_tools_to_path()
26 gsutil_exe = os.path.join(depot_tools_path, "third_party", "gsutil", "gsutil")
28 def download():
29 version_path = os.path.join(current_path, "../VERSION")
30 with open(version_path) as version_file:
31 version = version_file.read().strip()
33 try:
34 with open(stamp_path) as stamp_file:
35 current_version = stamp_file.read().strip()
36 if current_version == version:
37 return 0 # Already have the right version.
38 except IOError:
39 pass # If the stamp file does not exist we need to download a new binary.
41 platform = "linux-x64" # TODO: configurate
42 basename = platform + ".zip"
44 gs_path = "gs://mojo/shell/" + version + "/" + basename
46 with tempfile.NamedTemporaryFile() as temp_zip_file:
47 subprocess.check_call([gsutil_exe, "--bypass_prodaccess",
48 "cp", gs_path, temp_zip_file.name])
49 with zipfile.ZipFile(temp_zip_file.name) as z:
50 zi = z.getinfo("mojo_shell")
51 mode = zi.external_attr >> 16L
52 z.extract(zi, prebuilt_file_path)
53 os.chmod(os.path.join(prebuilt_file_path, "mojo_shell"), mode)
55 with open(stamp_path, 'w') as stamp_file:
56 stamp_file.write(version)
57 return 0
59 def main():
60 parser = argparse.ArgumentParser(description="Download mojo_shell binary "
61 "from google storage")
62 parser.parse_args()
63 return download()
65 if __name__ == "__main__":
66 sys.exit(main())