From 62493eb7b0326a880819615ad7a0405e23f5ac9c Mon Sep 17 00:00:00 2001 From: Shararamosh Date: Sat, 10 Aug 2024 19:08:30 +0300 Subject: [PATCH] Added logging_redirect_tqdm call and specified shell in build_executable.yml workflow. --- .github/workflows/build_executable.yml | 1 + main.py | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build_executable.yml b/.github/workflows/build_executable.yml index 37fc652..a791f71 100644 --- a/.github/workflows/build_executable.yml +++ b/.github/workflows/build_executable.yml @@ -20,6 +20,7 @@ jobs: run: pyinstaller --onefile --name="flatc_deserializer" --console --icon=images\flatbuffers-logo-clean.png --add-data="images:images" --add-data="localization:localization" main.py - name: Copy Executable from dist to root directory run: copy dist\flatc_deserializer.exe . + shell: cmd - name: Create Automatic Windows Release uses: marvinpinto/action-automatic-releases@latest with: diff --git a/main.py b/main.py index dbb2e4e..b28b6be 100644 --- a/main.py +++ b/main.py @@ -12,6 +12,7 @@ import i18n from PIL.ImageTk import PhotoImage from tqdm import tqdm +from tqdm.contrib.logging import logging_redirect_tqdm from flatc_funcs import deserialize # pylint: disable=import-error @@ -40,10 +41,10 @@ def get_resource_path(filename: str) -> str: root.iconphoto(True, PhotoImage(file=get_resource_path("images/flatbuffers-logo-clean.png"))) -def main() -> int: +def main() -> int | str: """ Десериализация бинарных файлов Flatbuffers по заданной схеме. - :return: Код ошибки. + :return: Код ошибки или строка об ошибке. """ flatc_path = askopenfilename(title=i18n.t("main.tkinter_flatc_select"), filetypes=[(i18n.t("main.exe_filetype"), "*.exe")]) @@ -59,14 +60,16 @@ def main() -> int: (i18n.t("main.flatc_binary_filetype"), "*." + schema_name)]) output_path = askdirectory(title=i18n.t("flatc_funcs.tkinter_output_select")) full_size = sum(os.stat(binary_path).st_size for binary_path in binary_paths) - pbar = tqdm(total=full_size, position=0, unit="B", unit_scale=True, desc=i18n.t("main.files")) - for binary_path in binary_paths: - pbar.set_postfix_str(binary_path) - pbar.clear() - deserialize(flatc_path, schema_path, binary_path, output_path) - pbar.update(os.stat(binary_path).st_size) - pbar.set_postfix_str("") - pbar.close() + with logging_redirect_tqdm(): + pbar = tqdm(total=full_size, position=0, unit="B", unit_scale=True, + desc=i18n.t("main.files")) + for binary_path in binary_paths: + pbar.set_postfix_str(binary_path) + pbar.clear() + deserialize(flatc_path, schema_path, binary_path, output_path) + pbar.update(os.stat(binary_path).st_size) + pbar.set_postfix_str("") + pbar.close() return os.EX_OK