From 3c43486cf5e8d31213c516da1336ab6ca3226a2c Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Thu, 29 Feb 2024 18:23:33 +0100 Subject: [PATCH] Colorama (#20838) --- pio-tools/gzip-firmware.py | 7 +++---- pio-tools/override_copy.py | 13 +++++++------ pio-tools/post_esp32.py | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pio-tools/gzip-firmware.py b/pio-tools/gzip-firmware.py index 79e61abd5..2ff4a7f5c 100644 --- a/pio-tools/gzip-firmware.py +++ b/pio-tools/gzip-firmware.py @@ -4,6 +4,7 @@ import os import shutil import tasmotapiolib import gzip +from colorama import Fore, Back, Style def map_gzip(source, target, env): # create string with location and file names based on variant @@ -50,14 +51,12 @@ if tasmotapiolib.is_env_set(tasmotapiolib.ENABLE_ESP32_GZ, env) or env["PIOPLATF GZ_FIRMWARE_SIZE = gzip_file.stat().st_size if ORG_FIRMWARE_SIZE > 995326 and env["PIOPLATFORM"] != "espressif32": - print( - "\u001b[31;1m!!! Tasmota firmware size is too big with {} bytes. Max size is 995326 bytes !!! \u001b[0m".format( + print(Fore.RED + "!!! Tasmota firmware size is too big with {} bytes. Max size is 995326 bytes !!! ".format( ORG_FIRMWARE_SIZE ) ) else: - print( - "Compression reduced firmware size to {:.0f}% (was {} bytes, now {} bytes)".format( + print(Fore.GREEN + "Compression reduced firmware size to {:.0f}% (was {} bytes, now {} bytes)".format( (GZ_FIRMWARE_SIZE / ORG_FIRMWARE_SIZE) * 100, ORG_FIRMWARE_SIZE, GZ_FIRMWARE_SIZE, diff --git a/pio-tools/override_copy.py b/pio-tools/override_copy.py index a52c62c85..5ad56ee49 100644 --- a/pio-tools/override_copy.py +++ b/pio-tools/override_copy.py @@ -4,30 +4,31 @@ import os import pathlib from os.path import join import shutil +from colorama import Fore, Back, Style if " " in join(pathlib.Path(env["PROJECT_DIR"])): - print ("\u001b[31;1m*** Whitespace(s) in project path, unexpected issues/errors can happen ***\u001b[0m") + print(Fore.RED + "*** Whitespace(s) in project path, unexpected issues/errors can happen ***") # copy tasmota/user_config_override_sample.h to tasmota/user_config_override.h if os.path.isfile("tasmota/user_config_override.h"): - print ("*** use provided user_config_override.h as planned ***") + print(Fore.GREEN + "*** use provided user_config_override.h as planned ***") else: shutil.copy("tasmota/user_config_override_sample.h", "tasmota/user_config_override.h") # copy platformio_override_sample.ini to platformio_override.ini if os.path.isfile("platformio_override.ini"): - print ("*** use provided platformio_override.ini as planned ***") + print(Fore.GREEN + "*** use provided platformio_override.ini as planned ***") else: shutil.copy("platformio_override_sample.ini", "platformio_override.ini") # copy platformio_tasmota_cenv_sample.ini to platformio_tasmota_cenv.ini if os.path.isfile("platformio_tasmota_cenv.ini"): - print ("*** use provided platformio_tasmota_cenv.ini as planned ***") + print(Fore.GREEN + "*** use provided platformio_tasmota_cenv.ini as planned ***") else: shutil.copy("platformio_tasmota_cenv_sample.ini", "platformio_tasmota_cenv.ini") # copy platformio_tasmota_core3_env_sample.ini to platformio_tasmota_core3_env.ini if os.path.isfile("platformio_tasmota_core3_env.ini"): - print ("*** use provided platformio_tasmota_core3_env.ini as planned ***") + print(Fore.GREEN + "*** use provided platformio_tasmota_core3_env.ini as planned ***") else: - shutil.copy("platformio_tasmota_core3_env_sample.ini", "platformio_tasmota_core3_env.ini") \ No newline at end of file + shutil.copy("platformio_tasmota_core3_env_sample.ini", "platformio_tasmota_core3_env.ini") diff --git a/pio-tools/post_esp32.py b/pio-tools/post_esp32.py index f50fd947e..aacf1d169 100644 --- a/pio-tools/post_esp32.py +++ b/pio-tools/post_esp32.py @@ -103,7 +103,7 @@ def esp32_detect_flashsize(): return size, True return "4MB",False except subprocess.CalledProcessError as exc: - print("Did get chip info failed with " + str(exc)) + print(Fore.YELLOW + "Did get chip info failed with " + str(exc)) return "4MB",False flash_size_from_esp, flash_size_was_overridden = esp32_detect_flashsize() @@ -166,7 +166,7 @@ def esp32_build_filesystem(fs_size): print("Renaming",(file.split(os.path.sep)[-1]).split(" ")[0],"to",file.split(" ")[1]) open(target, "wb").write(response.content) else: - print("Failed to download: ",file) + print(Fore.RED + "Failed to download: ",file) continue if os.path.isdir(file): shutil.copytree(file, filesystem_dir, dirs_exist_ok=True)