Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2016 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import os | 6 import os |
| 7 import shutil | 7 import shutil |
| 8 import sys | 8 import sys |
| 9 import subprocess | 9 import subprocess |
| 10 import tarfile | 10 import tarfile |
| 11 import tempfile | 11 import tempfile |
| 12 import urllib2 | 12 import urllib2 |
| 13 | 13 |
| 14 THIS_DIR = os.path.dirname(os.path.abspath(__file__)) | 14 THIS_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 15 | 15 |
| 16 DEFAULT_VERSION = '4.5.0' | 16 if len(sys.argv) < 2: |
| 17 print('Usage: {} <version>'.format(sys.argv[0])) | |
|
lushnikov
2016/10/12 22:10:19
you already have a way to pass Node version in via
chenwilliam
2016/10/17 19:32:27
Done.
| |
| 18 print(' <version> Specific node.js version (e.g. 4.5.0)') | |
| 19 sys.exit(1) | |
| 20 | |
| 21 DEFAULT_VERSION = sys.argv[1] | |
| 17 BUCKET = 'chromium-nodejs' | 22 BUCKET = 'chromium-nodejs' |
| 18 | 23 |
| 19 | 24 |
| 20 def install_latest_node_js(version, tmp_dir): | 25 def install_latest_node_js(version, tmp_dir): |
| 21 target_dir = os.path.join(THIS_DIR, 'runtimes', version) | 26 target_dir = os.path.join(THIS_DIR, 'runtimes', version) |
| 22 version_file = os.path.join(target_dir, 'VERSION') | 27 version_file = os.path.join(target_dir, 'VERSION') |
| 23 | 28 |
| 24 if sys.platform == 'win32': | 29 if sys.platform == 'win32': |
| 25 bin_location = os.path.join(target_dir, 'node.exe') | 30 bin_location = os.path.join(target_dir, 'node.exe') |
| 26 else: | 31 else: |
| 27 bin_location = os.path.join(target_dir, 'bin', 'node') | 32 bin_location = os.path.join(target_dir, 'bin', 'node') |
| 28 | 33 |
| 29 # We assume that, if the VERSION file exists, then the installation is good. | 34 # We assume that, if the VERSION file exists, then the installation is good. |
| 30 if os.path.exists(version_file): | 35 if os.path.exists(version_file): |
| 31 with open(version_file, 'r') as f: | 36 with open(version_file, 'r') as f: |
| 32 if f.read() == version: | 37 if f.read() == version: |
| 33 return bin_location | 38 return bin_location |
| 34 | 39 |
| 35 # TODO(hinoka): This probably doesn't work that well on Windows... | 40 # TODO(hinoka): This probably doesn't work that well on Windows... |
| 36 shutil.rmtree(target_dir, ignore_errors=True) | 41 shutil.rmtree(target_dir, ignore_errors=True) |
| 37 | 42 |
| 38 # Get the target name correct. | 43 # Get the target name correct. |
| 39 if sys.platform == 'win32': | 44 if sys.platform == 'win32': |
| 40 target = 'node.exe' | 45 target = 'node.exe' |
| 41 elif sys.platform == 'darwin': | 46 elif sys.platform == 'darwin': |
| 42 target = 'node-v%s-darwin-x86.tar.gz' % version | 47 target = 'node-v%s-darwin-x64.tar.gz' % version |
| 43 elif sys.platform == 'linux2': | 48 elif sys.platform == 'linux2': |
| 44 target = 'node-v%s-linux-x86.tar.gz' % version | 49 target = 'node-v%s-linux-x86.tar.gz' % version |
| 45 else: | 50 else: |
| 46 raise Exception('Unrecognized platform %s' % sys.platform) | 51 raise Exception('Unrecognized platform %s' % sys.platform) |
| 47 | 52 |
| 48 dest = os.path.join(tmp_dir, 'node_download') | 53 dest = os.path.join(tmp_dir, 'node_download') |
| 49 url = 'https://storage.googleapis.com/%s/%s/%s' % ( | 54 url = 'https://storage.googleapis.com/%s/%s/%s' % ( |
| 50 BUCKET, version, target) | 55 BUCKET, version, target) |
| 51 print('Fetching %s' % url) | 56 print('Fetching %s' % url) |
| 52 u = urllib2.urlopen(url) | 57 u = urllib2.urlopen(url) |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 tmp_dir = tempfile.mkdtemp(dir=THIS_DIR) | 110 tmp_dir = tempfile.mkdtemp(dir=THIS_DIR) |
| 106 bin_location = install_latest_node_js(version, tmp_dir) | 111 bin_location = install_latest_node_js(version, tmp_dir) |
| 107 finally: | 112 finally: |
| 108 if os.path.exists(tmp_dir): | 113 if os.path.exists(tmp_dir): |
| 109 shutil.rmtree(tmp_dir) | 114 shutil.rmtree(tmp_dir) |
| 110 | 115 |
| 111 if mode == 'npm': | 116 if mode == 'npm': |
| 112 # TODO(hinoka): How about Windows...? | 117 # TODO(hinoka): How about Windows...? |
| 113 bin_location = os.path.join(os.path.dirname(bin_location), 'npm') | 118 bin_location = os.path.join(os.path.dirname(bin_location), 'npm') |
| 114 | 119 |
| 115 return subprocess.call([bin_location, ] + sys.argv[1:]) | 120 return subprocess.call([bin_location, ] + sys.argv[2:]) |
| 116 | 121 |
| 117 | 122 |
| 118 if __name__ == '__main__': | 123 if __name__ == '__main__': |
| 119 sys.exit(main()) | 124 sys.exit(main()) |
| OLD | NEW |