diff --git a/script/lib/util.py b/script/lib/util.py index b71e5838be8d..51ca69dc378e 100644 --- a/script/lib/util.py +++ b/script/lib/util.py @@ -1,20 +1,27 @@ +#!/usr/bin/env python + import atexit +import errno import shutil import tarfile import tempfile import urllib2 +import os -def download(text, url, filename): - directory = tempfile.mkdtemp(prefix='atom-shell-') +def tempdir(prefix=''): + directory = tempfile.mkdtemp(prefix=prefix) atexit.register(shutil.rmtree, directory) + return directory - web_file = urllib2.urlopen(url) - file_size = int(web_file.info().getheaders("Content-Length")[0]) - downloaded_size = 0 - block_size = 128 - with open(os.path.join(directory, filename), 'w+') as local_file: +def download(text, url, path): + with open(path, 'w') as local_file: + web_file = urllib2.urlopen(url) + file_size = int(web_file.info().getheaders("Content-Length")[0]) + downloaded_size = 0 + block_size = 128 + while True: buf = web_file.read(block_size) if not buf: @@ -29,8 +36,6 @@ def download(text, url, filename): print - return directory - def extract_tarball(tarball_path, member, path): with tarfile.open(tarball_path) as tarball: diff --git a/script/update-node.py b/script/update-node.py index bfa2aa07492d..caadb3c8ff8c 100755 --- a/script/update-node.py +++ b/script/update-node.py @@ -23,12 +23,14 @@ def main(): return 0 url, filename = get_node_url(args.url, args.version) - directory = download('Download node', url, filename) + directory = tempdir(prefix='atom-shell-') + path = os.path.join(directory, filename) + download('Download node', url, path) if IS_POSIX: root_name = 'node-{0}-{1}-x86'.format(args.version, sys.platform) member = os.path.join(root_name, 'bin', 'node') - extract_tarball(os.path.join(directory, filename), member, directory) + extract_tarball(path, member, directory) node_path = os.path.join(directory, member) copy_node(node_path)