Files
firefox/testing/web-platform/tests/mathml/tools/utils/misc.py
T
Ms2ger 7cb0c6603e Bug 1442264 [wpt PR 8839] - Make more python code parse as python3., a=testonly
Automatic update from web-platform-testsUse the print function in some scripts.

--
Use Python3-compatible except syntax.

--
Prepare mathml/tools/utils/misc.py for python3.

wpt-commits: f1536eed16c7b743acbf9188150041f049b646b9, b762b7fa54e2e830b6e400fc5d8c369c95c53e82, 911d525247327484c66ef851d6219a9ef555b0ac
wpt-pr: 8839
wpt-commits: f1536eed16c7b743acbf9188150041f049b646b9, b762b7fa54e2e830b6e400fc5d8c369c95c53e82, 911d525247327484c66ef851d6219a9ef555b0ac
wpt-pr: 8839
2018-03-31 22:28:31 +01:00

37 lines
1019 B
Python

from __future__ import print_function
import os
import progressbar
try:
from urllib.request import urlopen
except ImportError:
from urllib2 import urlopen
MathMLAssociationCopyright = "Copyright (c) 2016 MathML Association"
def downloadWithProgressBar(url, outputDirectory="./", forceDownload=False):
baseName = os.path.basename(url)
fileName = os.path.join(outputDirectory, baseName)
if not forceDownload and os.path.exists(fileName):
return fileName
request = urlopen(url)
totalSize = int(request.info().getheader('Content-Length').strip())
bar = progressbar.ProgressBar(maxval=totalSize).start()
chunkSize = 16 * 1024
downloaded = 0
print("Downloading %s" % url)
os.umask(0o002)
with open(fileName, 'wb') as fp:
while True:
chunk = request.read(chunkSize)
downloaded += len(chunk)
bar.update(downloaded)
if not chunk: break
fp.write(chunk)
bar.finish()
return fileName