From 63b6cee1a19a53f9817fe1351672a81d6aa4f152 Mon Sep 17 00:00:00 2001 From: Hadinger Date: Tue, 7 Jan 2020 22:32:48 +0100 Subject: [PATCH] Make gzip Python2.7 compatible --- pio/gzip-firmware.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/pio/gzip-firmware.py b/pio/gzip-firmware.py index 1061f1010..e8fae2c92 100644 --- a/pio/gzip-firmware.py +++ b/pio/gzip-firmware.py @@ -13,17 +13,11 @@ def bin_gzip(source, target, env): gzip_file = "{}firmware{}{}.bin.gz".format(OUTPUT_DIR, os.path.sep, variant) # check if new target files exist and remove if necessary - for f in [gzip_file]: - if os.path.isfile(f): - os.remove(f) + if os.path.isfile(gzip_file): os.remove(gzip_file) # write gzip firmware file - fp = open(bin_file,"rb") - data = fp.read() - bindata = bytearray(data) - with gzip.open(gzip_file, "wb") as f: - f.write(bindata) - fp.close() - f.close() + with open(bin_file,"rb") as fp: + with gzip.open(gzip_file, "wb") as f: + shutil.copyfileobj(fp, f) env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", [bin_gzip])