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

Side by Side 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, 5 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 unified diff | Download patch
« no previous file with comments | « no previous file | tools/download_prebuilt_sdk.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright 2016 The Dart project 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 # This script downloads the latest dev SDK from
7 # http://gsdview.appspot.com/dart-archive/channels/dev/raw/latest/sdk/
8 # into tools/sdks/$HOST_OS/. It is intended to be invoked from Jiri hooks in
9 # a Fuchsia checkout.
10
11 import os
12 import sys
13 import zipfile
14 import urllib
15 import utils
16
17 HOST_OS = utils.GuessOS()
18 HOST_ARCH = utils.GuessArchitecture()
19 SCRIPT_DIR = os.path.dirname(sys.argv[0])
20 DART_ROOT = os.path.realpath(os.path.join(SCRIPT_DIR, '..'))
21
22 BASE_URL = 'http://gsdview.appspot.com/dart-archive/channels/dev/raw/latest/sdk'
23
24 def host_os_for_sdk(host_os):
25 if host_os.startswith('macos'):
26 return 'mac'
27 if host_os.startswith('win'):
28 return 'windows'
29 return host_os
30
31 # Python's zipfile doesn't preserve file permissions during extraction, so we
32 # have to do it manually.
33 def extract_file(zf, info, extract_dir):
34 zf.extract( info.filename, path=extract_dir )
35 out_path = os.path.join(extract_dir, info.filename)
36 perm = info.external_attr >> 16L
37 os.chmod(out_path, perm)
38
39 def main(argv):
40 host_os = host_os_for_sdk(HOST_OS)
41 zip_file = ('dartsdk-%s-x64-release.zip' % HOST_OS)
42 sha_file = zip_file + '.sha256sum'
43 sdk_path = os.path.join(DART_ROOT, 'tools', 'sdks', host_os)
44 local_sha_path = os.path.join(sdk_path, sha_file)
45 remote_sha_path = os.path.join(sdk_path, sha_file + '.remote')
46 zip_path = os.path.join(sdk_path, zip_file)
47 sha_url = BASE_URL + '/' + sha_file
48 zip_url = BASE_URL + '/' + zip_file
49
50 local_sha = ''
51 if os.path.isfile(local_sha_path):
52 with open(local_sha_path, 'r') as fp:
53 local_sha = fp.read()
54
55 remote_sha = ''
56 urllib.urlretrieve(sha_url, remote_sha_path)
57 with open(remote_sha_path, 'r') as fp:
58 remote_sha = fp.read()
59 os.remove(remote_sha_path)
60
61 if local_sha == '' or local_sha != remote_sha:
62 with open(local_sha_path, 'w') as fp:
63 fp.write(remote_sha)
64 print 'Downloading prebuilt Dart SDK from: ' + zip_url
65 urllib.urlretrieve(zip_url, zip_path)
66 with zipfile.ZipFile(zip_path, 'r') as zf:
67 for info in zf.infolist():
68 extract_file(zf, info, sdk_path)
69
70 if __name__ == '__main__':
71 sys.exit(main(sys.argv))
OLDNEW
« 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