From 020619fa97cd6d8ce7a984c9c48d4625a2de0d04 Mon Sep 17 00:00:00 2001 From: Alexandre Lissy Date: Tue, 18 Feb 2020 12:55:10 +0100 Subject: [PATCH] Automagically decompress GZipped artifacts Fixes #2760 --- util/taskcluster.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/util/taskcluster.py b/util/taskcluster.py index 39560227..9116a759 100644 --- a/util/taskcluster.py +++ b/util/taskcluster.py @@ -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):