Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Unified Diff: tools/download_latest_dev_sdk.py

Issue 2959973002: [Fuchsia] Script for downloading the latest prebuilt dev SDK (Closed)
Patch Set: Preserve file permissions Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/download_prebuilt_sdk.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/download_latest_dev_sdk.py
diff --git a/tools/download_latest_dev_sdk.py b/tools/download_latest_dev_sdk.py
new file mode 100755
index 0000000000000000000000000000000000000000..3c212566ec2d32ee0b74e7af7b88723690b272a7
--- /dev/null
+++ b/tools/download_latest_dev_sdk.py
@@ -0,0 +1,71 @@
+#!/usr/bin/env python
+# Copyright 2016 The Dart project authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# This script downloads the latest dev SDK from
+# http://gsdview.appspot.com/dart-archive/channels/dev/raw/latest/sdk/
+# into tools/sdks/$HOST_OS/. It is intended to be invoked from Jiri hooks in
+# a Fuchsia checkout.
+
+import os
+import sys
+import zipfile
+import urllib
+import utils
+
+HOST_OS = utils.GuessOS()
+HOST_ARCH = utils.GuessArchitecture()
+SCRIPT_DIR = os.path.dirname(sys.argv[0])
+DART_ROOT = os.path.realpath(os.path.join(SCRIPT_DIR, '..'))
+
+BASE_URL = 'http://gsdview.appspot.com/dart-archive/channels/dev/raw/latest/sdk'
+
+def host_os_for_sdk(host_os):
+ if host_os.startswith('macos'):
+ return 'mac'
+ if host_os.startswith('win'):
+ return 'windows'
+ return host_os
+
+# Python's zipfile doesn't preserve file permissions during extraction, so we
+# have to do it manually.
+def extract_file(zf, info, extract_dir):
+ zf.extract( info.filename, path=extract_dir )
+ out_path = os.path.join(extract_dir, info.filename)
+ perm = info.external_attr >> 16L
+ os.chmod(out_path, perm)
+
+def main(argv):
+ host_os = host_os_for_sdk(HOST_OS)
+ zip_file = ('dartsdk-%s-x64-release.zip' % HOST_OS)
+ sha_file = zip_file + '.sha256sum'
+ sdk_path = os.path.join(DART_ROOT, 'tools', 'sdks', host_os)
+ local_sha_path = os.path.join(sdk_path, sha_file)
+ remote_sha_path = os.path.join(sdk_path, sha_file + '.remote')
+ zip_path = os.path.join(sdk_path, zip_file)
+ sha_url = BASE_URL + '/' + sha_file
+ zip_url = BASE_URL + '/' + zip_file
+
+ local_sha = ''
+ if os.path.isfile(local_sha_path):
+ with open(local_sha_path, 'r') as fp:
+ local_sha = fp.read()
+
+ remote_sha = ''
+ urllib.urlretrieve(sha_url, remote_sha_path)
+ with open(remote_sha_path, 'r') as fp:
+ remote_sha = fp.read()
+ os.remove(remote_sha_path)
+
+ if local_sha == '' or local_sha != remote_sha:
+ with open(local_sha_path, 'w') as fp:
+ fp.write(remote_sha)
+ print 'Downloading prebuilt Dart SDK from: ' + zip_url
+ urllib.urlretrieve(zip_url, zip_path)
+ with zipfile.ZipFile(zip_path, 'r') as zf:
+ for info in zf.infolist():
+ extract_file(zf, info, sdk_path)
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))
« no previous file with comments | « no previous file | tools/download_prebuilt_sdk.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698