tools: make nodedownload.py Python 3 compatible
PR-URL: https://github.com/nodejs/node/pull/29104 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
parent
6d351d4cc0
commit
8ae79c952b
@ -2,27 +2,29 @@
|
|||||||
# Moved some utilities here from ../../configure
|
# Moved some utilities here from ../../configure
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import urllib
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import sys
|
import sys
|
||||||
import zipfile
|
import zipfile
|
||||||
import tarfile
|
import tarfile
|
||||||
import fpformat
|
|
||||||
import contextlib
|
import contextlib
|
||||||
|
try:
|
||||||
|
from urllib.request import FancyURLopener, URLopener
|
||||||
|
except ImportError:
|
||||||
|
from urllib import FancyURLopener, URLopener
|
||||||
|
|
||||||
def formatSize(amt):
|
def formatSize(amt):
|
||||||
"""Format a size as a string in MB"""
|
"""Format a size as a string in MB"""
|
||||||
return fpformat.fix(amt / 1024000., 1)
|
return "%.1f" % (amt / 1024000.)
|
||||||
|
|
||||||
def spin(c):
|
def spin(c):
|
||||||
"""print out an ASCII 'spinner' based on the value of counter 'c'"""
|
"""print out an ASCII 'spinner' based on the value of counter 'c'"""
|
||||||
spin = ".:|'"
|
spin = ".:|'"
|
||||||
return (spin[c % len(spin)])
|
return (spin[c % len(spin)])
|
||||||
|
|
||||||
class ConfigOpener(urllib.FancyURLopener):
|
class ConfigOpener(FancyURLopener):
|
||||||
"""fancy opener used by retrievefile. Set a UA"""
|
"""fancy opener used by retrievefile. Set a UA"""
|
||||||
# append to existing version (UA)
|
# append to existing version (UA)
|
||||||
version = '%s node.js/configure' % urllib.URLopener.version
|
version = '%s node.js/configure' % URLopener.version
|
||||||
|
|
||||||
def reporthook(count, size, total):
|
def reporthook(count, size, total):
|
||||||
"""internal hook used by retrievefile"""
|
"""internal hook used by retrievefile"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user