Merge pull request #2768 from lissyx/auto-decompress-artifacts

Automagically decompress GZipped artifacts
This commit is contained in:
lissyx 2020-02-18 15:29:46 +01:00 committed by GitHub
commit 47f702bf37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 1 deletions

View File

@ -9,6 +9,7 @@ import sys
import os
import errno
import stat
import gzip
import six.moves.urllib as urllib
@ -52,12 +53,21 @@ def maybe_download_tc(target_dir, tc_url, progress=True):
tc_filename = os.path.basename(tc_url)
target_file = os.path.join(target_dir, tc_filename)
is_gzip = False
if not os.path.isfile(target_file):
print('Downloading %s ...' % tc_url)
urllib.request.urlretrieve(tc_url, target_file, reporthook=(report_progress if progress else None))
_, headers = urllib.request.urlretrieve(tc_url, target_file, reporthook=(report_progress if progress else None))
is_gzip = headers.get('Content-Encoding') == 'gzip'
else:
print('File already exists: %s' % target_file)
if is_gzip:
with open(target_file, "r+b") as frw:
decompressed = gzip.decompress(frw.read())
frw.seek(0)
frw.write(decompressed)
frw.truncate()
return target_file
def maybe_download_tc_bin(**kwargs):