Tasmota/pio/gzip-firmware.py

24 lines
771 B
Python
Raw Normal View History

2020-01-07 12:08:30 +00:00
Import('env')
import os
import shutil
import gzip
OUTPUT_DIR = "build_output{}".format(os.path.sep)
def bin_gzip(source, target, env):
variant = str(target[0]).split(os.path.sep)[1]
# create string with location and file names based on variant
bin_file = "{}firmware{}{}.bin".format(OUTPUT_DIR, os.path.sep, variant)
gzip_file = "{}firmware{}{}.bin.gz".format(OUTPUT_DIR, os.path.sep, variant)
# check if new target files exist and remove if necessary
2020-01-07 21:32:48 +00:00
if os.path.isfile(gzip_file): os.remove(gzip_file)
2020-01-07 12:08:30 +00:00
# write gzip firmware file
2020-01-07 21:32:48 +00:00
with open(bin_file,"rb") as fp:
with gzip.open(gzip_file, "wb") as f:
shutil.copyfileobj(fp, f)
2020-01-07 12:08:30 +00:00
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", [bin_gzip])