mirror of
https://github.com/danbulant/deno_install
synced 2026-07-05 11:10:50 +00:00
feat: show progress indicator
This commit is contained in:
parent
99590073b4
commit
b6b938f744
1 changed files with 25 additions and 2 deletions
27
install.py
27
install.py
|
|
@ -55,13 +55,36 @@ def release_url(platform, tag):
|
||||||
return "https://github.com" + matching[0]
|
return "https://github.com" + matching[0]
|
||||||
|
|
||||||
|
|
||||||
|
def download_with_progress(url):
|
||||||
|
print("Downloading", url)
|
||||||
|
|
||||||
|
remote_file = urlopen(url)
|
||||||
|
total_size = int(remote_file.headers['Content-Length'].strip())
|
||||||
|
|
||||||
|
data = []
|
||||||
|
bytes_read = 0.0
|
||||||
|
|
||||||
|
while True:
|
||||||
|
d = remote_file.read(8192)
|
||||||
|
|
||||||
|
if not d:
|
||||||
|
print()
|
||||||
|
break
|
||||||
|
|
||||||
|
bytes_read += len(d)
|
||||||
|
data.append(d)
|
||||||
|
sys.stdout.write('\r%2.2f%% downloaded' % (bytes_read / total_size * 100))
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
return b''.join(data)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
bin_dir = deno_bin_dir()
|
bin_dir = deno_bin_dir()
|
||||||
exe_fn = os.path.join(bin_dir, "deno")
|
exe_fn = os.path.join(bin_dir, "deno")
|
||||||
|
|
||||||
url = release_url(sys.platform, sys.argv[1] if len(sys.argv) > 1 else None)
|
url = release_url(sys.platform, sys.argv[1] if len(sys.argv) > 1 else None)
|
||||||
print("Downloading", url)
|
compressed = download_with_progress(url)
|
||||||
compressed = urlopen(url).read()
|
|
||||||
|
|
||||||
if url.endswith(".zip"):
|
if url.endswith(".zip"):
|
||||||
with zipfile.ZipFile(io.BytesIO(compressed), 'r') as z:
|
with zipfile.ZipFile(io.BytesIO(compressed), 'r') as z:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue