Skip to content

Commit

Permalink
Exceptions no longer output traceback, flatc_downloader no longer req…
Browse files Browse the repository at this point in the history
…uires downloads directory positional argument.
  • Loading branch information
Shararamosh committed Sep 12, 2024
1 parent 0475bd6 commit f389d0a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion flatc_deserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from main import prepare_app, get_flatc_path, execute_deserialize

if __name__ == "__main__":
sys.tracebacklimit = 0
prepare_app("images/flatbuffers-logo-clean.png")
parser = argparse.ArgumentParser(prog=t("main.flatc_deserializer_name"),
description=t("main.flatc_deserializer_desc"))
Expand All @@ -21,5 +22,5 @@
parser.add_argument("-f", "--flatc_path", type=str, default="", help=t("main.flatc_path_arg"))
args = parser.parse_args()
sys.exit(execute_deserialize(
get_flatc_path(os.getcwd(), True) if args.flatc_path == "" else args.flatc_path,
get_flatc_path(os.getcwd(), True, False) if args.flatc_path == "" else args.flatc_path,
args.schema_path, args.binary_paths, args.output_path))
3 changes: 2 additions & 1 deletion flatc_deserializer_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from main import prepare_app, get_flatc_path, execute_deserialize_batch

if __name__ == "__main__":
sys.tracebacklimit = 0
prepare_app("images/flatbuffers-batch-logo-clean.png")
parser = argparse.ArgumentParser(prog=t("main.flatc_deserializer_name"),
description=t("main.flatc_derializer_desc"))
Expand All @@ -23,5 +24,5 @@
parser.add_argument("-f", "--flatc_path", type=str, default="", help=t("main.flatc_path_arg"))
args = parser.parse_args()
sys.exit(execute_deserialize_batch(
get_flatc_path(os.getcwd(), True) if args.flatc_path == "" else args.flatc_path,
get_flatc_path(os.getcwd(), True, False) if args.flatc_path == "" else args.flatc_path,
args.schemas_path, args.binaries_path, args.output_path))
3 changes: 2 additions & 1 deletion flatc_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
from main import prepare_app, execute_download

if __name__ == "__main__":
sys.tracebacklimit = 0
prepare_app("images/flatbuffers-downloader-logo-clean.png")
parser = argparse.ArgumentParser(prog=t("main.flatc_downloader_name"),
description=t("main.flatc_downloader_desc"))
parser.add_argument("downloads_directory", type=str, default=os.getcwd(),
parser.add_argument("downloads_directory", nargs="?", type=str, default=os.getcwd(),
help=t("main.download_directory_arg"))
args = parser.parse_args()
sys.exit(execute_download(args.downloads_directory))
10 changes: 7 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ def prepare_app(icon_path: str):
root.iconphoto(True, PhotoImage(file=get_resource_path(icon_path)))


def get_flatc_path(root_path: str, allow_ask: bool, suppress_ask_error: bool = True) -> str:
def get_flatc_path(root_path: str, allow_ask: bool, suppress_error: bool) -> str:
"""
Получение пути к файлу компилятора Flatbuffers.
:param root_path: Путь к текущей рабочей директории.
:param allow_ask: Позволить открыть файл через диалоговое окно, если файла нет в рабочей директории.
:param suppress_ask_error: Игнорировать ошибку FileNotFoundError, если не выводится диалоговое окно для файла.
:param suppress_error: Игнорировать ошибку FileNotFoundError.
:return: Путь к файлу.
"""
flatc_path = which("flatc", path=root_path + os.sep)
if flatc_path is not None:
return os.path.abspath(flatc_path)
if not allow_ask:
if suppress_ask_error:
if suppress_error:
return ""
raise FileNotFoundError(i18n.t("main.executable_not_found") % "flatc")
if sys.platform == "win32":
Expand All @@ -72,9 +72,13 @@ def get_flatc_path(root_path: str, allow_ask: bool, suppress_ask_error: bool = T
filetypes = []
flatc_path = askopenfilename(title=i18n.t("main.tkinter_flatc_select"), filetypes=filetypes)
if flatc_path == "":
if suppress_error:
return ""
raise FileNotFoundError(i18n.t("main.executable_not_found") % "flatc")
flatc_path = which(os.path.split(flatc_path)[1], path=os.path.split(flatc_path)[0])
if flatc_path is None:
if suppress_error:
return ""
raise FileNotFoundError(i18n.t("main.executable_not_found") % "flatc")
return os.path.abspath(flatc_path)

Expand Down

0 comments on commit f389d0a

Please sign in to comment.