From 87e326d976c73053f480c84fc4109eb7b56456df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Tronel?= Date: Sat, 29 Aug 2026 13:50:46 +0200 Subject: [PATCH] Remove function to discover if required tools are installed. --- src/tscut/tools/discovery.py | 51 ++++++++++++++++++++++++++++++++++++ src/tscut/tscut.py | 39 --------------------------- 2 files changed, 51 insertions(+), 39 deletions(-) create mode 100644 src/tscut/tools/discovery.py diff --git a/src/tscut/tools/discovery.py b/src/tscut/tools/discovery.py new file mode 100644 index 0000000..94d28a5 --- /dev/null +++ b/src/tscut/tools/discovery.py @@ -0,0 +1,51 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Copyright (C) 2026 Frédéric Tronel + + +import logging +from shutil import which + +from typeguard import typechecked + + +class MissingToolError(Exception): + pass + +@typechecked +def check_required_tools() -> tuple[bool,dict[str,str]]: + """ + Checks if all required external tools are installed. + + This function verifies the presence of required and optional external tools on the system. + It returns a tuple containing a boolean indicating whether all optional tools are installed, + along with a dictionary containing the paths to all tools. + + Args: + None + + Returns: + tuple[bool, dict[str, str]]: + - bool: True if all optional tools are installed, False otherwise + - dict[str, str]: dictionary containing the paths to all tools + """ + logger = logging.getLogger(__name__) + all_optional_tools = True + paths = {} + required = ['ffmpeg', 'ffprobe', 'mkvmerge', 'mkvinfo'] + optional = ['mkvextract', 'vobsubocr','tesseract'] + for tool in required: + path = which(tool) + if path is None: + logger.error('Required tool: %s is missing.',tool) + raise MissingToolError(tool) + paths[tool] = path + for tool in optional: + path = which(tool) + if path is None: + logger.info('Optional tool: %s is missing.',tool) + all_optional_tools = False + else: + paths[tool] = path + + return all_optional_tools, paths diff --git a/src/tscut/tscut.py b/src/tscut/tscut.py index 37b4621..7eada87 100755 --- a/src/tscut/tscut.py +++ b/src/tscut/tscut.py @@ -21,7 +21,6 @@ from os import ( set_inheritable, write, ) -from shutil import which from subprocess import PIPE, Popen from sys import exit from typing import IO @@ -82,44 +81,6 @@ from tscut.tools.timeframe import ( # Then finally, change the Private Codec Data in the final MKV. -@typechecked -def check_required_tools() -> tuple[bool,dict[str,str]]: - """ - Checks if all required external tools are installed. - - This function verifies the presence of required and optional external tools on the system. - It returns a tuple containing a boolean indicating whether all optional tools are installed, - along with a dictionary containing the paths to all tools. - - Args: - None - - Returns: - tuple[bool, dict[str, str]]: - - bool: True if all optional tools are installed, False otherwise - - dict[str, str]: dictionary containing the paths to all tools - """ - logger = logging.getLogger(__name__) - all_optional_tools = True - paths = {} - required = ['ffmpeg', 'ffprobe', 'mkvmerge', 'mkvinfo'] - optional = ['mkvextract', 'vobsubocr','tesseract'] - for tool in required: - path = which(tool) - if path is None: - logger.error('Required tool: %s is missing.',tool) - exit(-1) - else: - paths[tool] = path - for tool in optional: - path = which(tool) - if path is None: - logger.info('Optional tool: %s is missing.',tool) - all_optional_tools = False - else: - paths[tool] = path - - return all_optional_tools, paths @typechecked def get_tesseract_supported_lang(tesseract_path:str) -> dict[Lang, str]|None: