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.
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"
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")
29 version_path
= os
.path
.join(current_path
, "../VERSION")
30 with
open(version_path
) as version_file
:
31 version
= version_file
.read().strip()
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.
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
)
60 parser
= argparse
.ArgumentParser(description
="Download mojo_shell binary "
61 "from google storage")
65 if __name__
== "__main__":