Created
October 31, 2019 18:00
-
-
Save TerrorJack/f3ccbc80e73bd0d9207ea17c15c33813 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from io import BytesIO | |
import json | |
import os | |
from sys import argv | |
import tarfile | |
from urllib.request import urlopen | |
def get_bytes(url): | |
return urlopen(url).read() | |
def get_str(url): | |
return get_bytes(url).decode() | |
def get_index(chan): | |
return json.loads(get_bytes("https://nodejs.org/download/{0}/index.json".format(chan))) | |
def get_linux_x64_ver(idx): | |
for item in idx: | |
if "linux-x64" in item["files"]: | |
return item["version"] | |
def get_linux_x64_url(chan, ver): | |
return "https://nodejs.org/download/{0}/{1}/node-{1}-linux-x64.tar.xz".format(chan, ver) | |
def get_linux_x64_bytes(chan, ver): | |
return get_bytes(get_linux_x64_url(chan, ver)) | |
def get_linux_x64_tar(chan, ver): | |
return tarfile.open(mode="r:xz", fileobj=BytesIO(get_linux_x64_bytes(chan, ver))) | |
def extract_linux_x64_tar(chan, ver, path): | |
get_linux_x64_tar(chan, ver).extractall(path=path) | |
if __name__ == "__main__": | |
chan = argv[1] | |
ver = get_linux_x64_ver(get_index(chan)) | |
extract_linux_x64_tar(chan, ver, os.getcwd()) | |
print("node-{0}-linux-x64".format(ver), end="") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment