Chromium Code Reviews| Index: mojo/public/tools/download_network_service.py |
| diff --git a/mojo/public/tools/download_network_service.py b/mojo/public/tools/download_network_service.py |
| index 82951514a751f4c05a90b025007584c878302634..ec5530f676276c73b2338b20cc42c35f69d8967d 100755 |
| --- a/mojo/public/tools/download_network_service.py |
| +++ b/mojo/public/tools/download_network_service.py |
| @@ -4,6 +4,7 @@ |
| # found in the LICENSE file. |
| import argparse |
| +import gs |
| import os |
| import sys |
| import tempfile |
| @@ -11,23 +12,16 @@ import zipfile |
| _PLATFORMS = ["linux-x64", "android-arm"] |
| _APPS = ["network_service", "network_service_apptests"] |
| +_CURRENT_PATH = os.path.dirname(os.path.realpath(__file__)) |
| if not sys.platform.startswith("linux"): |
| print "Not supported for your platform" |
| sys.exit(0) |
| -# Add //tools to the system path so that we can import the gs helper. |
| script_dir = os.path.dirname(os.path.realpath(__file__)) |
| -# TODO(blundell): Determine whether to move gs.py into the SDK or to inline the |
| -# contents of that function in this file as is done in download_shell_binary.py. |
| -tools_path = os.path.join(script_dir, os.pardir, os.pardir, os.pardir, "tools") |
| -sys.path.insert(0, tools_path) |
| -# pylint: disable=F0401 |
| -import gs |
| - |
| -def download_app(app, version): |
| +def download_app(app, version, tools_directory): |
| prebuilt_directory = os.path.join(script_dir, "prebuilt/%s" % app) |
| stamp_path = os.path.join(prebuilt_directory, "VERSION") |
| @@ -40,19 +34,21 @@ def download_app(app, version): |
| pass # If the stamp file does not exist we need to download a new binary. |
| for platform in _PLATFORMS: |
| - download_app_for_platform(app, version, platform) |
| + download_app_for_platform(app, version, platform, tools_directory) |
| with open(stamp_path, 'w') as stamp_file: |
| stamp_file.write(version) |
| -def download_app_for_platform(app, version, platform): |
| +def download_app_for_platform(app, version, platform, tools_directory): |
| + find_depot_tools_path = os.path.join(_CURRENT_PATH, tools_directory) |
| binary_name = app + ".mojo" |
| gs_path = "gs://mojo/%s/%s/%s/%s.zip" % (app, version, platform, binary_name) |
| output_directory = os.path.join(script_dir, |
| "prebuilt/%s/%s" % (app, platform)) |
| with tempfile.NamedTemporaryFile() as temp_zip_file: |
| - gs.download_from_public_bucket(gs_path, temp_zip_file.name) |
| + gs.download_from_public_bucket(gs_path, temp_zip_file.name, |
| + find_depot_tools_path) |
| with zipfile.ZipFile(temp_zip_file.name) as z: |
| zi = z.getinfo(binary_name) |
| mode = zi.external_attr >> 16 |
| @@ -63,14 +59,24 @@ def main(): |
| parser = argparse.ArgumentParser( |
| description="Download prebuilt network service binaries from google " + |
| "storage") |
| - parser.parse_args() |
| + parser.add_argument("--tools-directory", |
| + dest="tools_directory", |
| + metavar="<tools-directory>", |
| + type=str, |
| + help="Path to the directory containing" |
| + " find_depot_tools.py, specified as a relative path" |
|
viettrungluu
2015/02/11 23:54:49
<bikeshed>On a multiple-line concatenation of stri
blundell
2015/02/12 09:06:33
A quick-and-dirty non-scientific search indicates
|
| + " from the location of this file.") |
| + args = parser.parse_args() |
| + if not args.tools_directory: |
| + print "Must specify --tools-directory; please see help message." |
|
viettrungluu
2015/02/11 23:54:49
I believe you can just add required=True to add_ar
blundell
2015/02/12 09:06:33
Nice! Done.
|
| + sys.exit(1) |
| version_path = os.path.join(script_dir, "NETWORK_SERVICE_VERSION") |
| with open(version_path) as version_file: |
| version = version_file.read().strip() |
| for app in _APPS: |
| - download_app(app, version) |
| + download_app(app, version, args.tools_directory) |
| return 0 |