electron/script/update-node.py

82 lines
2.1 KiB
Python
Raw Normal View History

2013-06-20 14:49:11 +00:00
#!/usr/bin/env python
2013-06-20 14:49:11 +00:00
import argparse
import errno
import subprocess
import sys
import os
from lib.util import *
SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
2013-06-20 14:49:11 +00:00
NODE_VERSION = 'v0.10.9'
NODE_DIST_URL = 'https://gh-contractor-zcbenz.s3.amazonaws.com/node/dist'
IS_POSIX = (sys.platform != 'win32') and (sys.platform != 'cygwin')
2013-06-20 14:49:11 +00:00
def main():
os.chdir(SOURCE_ROOT)
2013-06-20 14:49:11 +00:00
args = parse_args()
if not node_needs_update(args.version):
return 0
2013-06-20 14:49:11 +00:00
url, filename = get_node_url(args.url, args.version)
2013-06-20 15:10:00 +00:00
directory = tempdir(prefix='atom-shell-')
path = os.path.join(directory, filename)
download('Download node', url, path)
2013-06-20 14:49:11 +00:00
if IS_POSIX:
root_name = 'node-{0}-{1}-x86'.format(args.version, sys.platform)
member = os.path.join(root_name, 'bin', 'node')
2013-06-20 15:10:00 +00:00
extract_tarball(path, member, directory)
2013-06-20 14:49:11 +00:00
node_path = os.path.join(directory, member)
copy_node(node_path)
def parse_args():
parser = argparse.ArgumentParser(description='Update node binary')
parser.add_argument('--version',
help='Version of node',
default=NODE_VERSION,
required=False)
parser.add_argument('--url',
help='URL to download node',
default=NODE_DIST_URL,
required=False)
return parser.parse_args()
def node_needs_update(target_version):
try:
node = os.path.join('node', 'node')
if not IS_POSIX:
node += '.exe'
version = subprocess.check_output([node, '--version'])
return version.strip() != target_version
except OSError as e:
if e.errno != errno.ENOENT:
raise
return True
def get_node_url(base_url, target_version):
if IS_POSIX:
distname = 'node-{0}-{1}-x86.tar.gz'.format(target_version, sys.platform)
else:
distname = 'node-{0}.exe'.format(target_version)
return '{0}/{1}'.format(base_url, distname), distname
def copy_node(node_path):
safe_mkdir('node')
node = os.path.join('node', 'node')
safe_unlink(node)
os.rename(node_path, node)
if __name__ == '__main__':
sys.exit(main())