From f05761174fe70e552672b251eb96ea0347971175 Mon Sep 17 00:00:00 2001 From: cclauss Date: Tue, 13 Aug 2019 14:26:35 +0200 Subject: [PATCH] tools: make nodedownload.py Python 3 compatible --- tools/configure.d/nodedownload.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tools/configure.d/nodedownload.py b/tools/configure.d/nodedownload.py index 53d2692ed15dca..515704e3de4763 100644 --- a/tools/configure.d/nodedownload.py +++ b/tools/configure.d/nodedownload.py @@ -2,27 +2,29 @@ # Moved some utilities here from ../../configure from __future__ import print_function -import urllib import hashlib import sys import zipfile import tarfile -import fpformat import contextlib +try: + from urllib.request import FancyURLopener, URLopener +except ImportError: + from urllib import FancyURLopener, URLopener def formatSize(amt): """Format a size as a string in MB""" - return fpformat.fix(amt / 1024000., 1) + return "%.1f" % (amt / 1024000.) def spin(c): """print out an ASCII 'spinner' based on the value of counter 'c'""" spin = ".:|'" return (spin[c % len(spin)]) -class ConfigOpener(urllib.FancyURLopener): +class ConfigOpener(FancyURLopener): """fancy opener used by retrievefile. Set a 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): """internal hook used by retrievefile"""