Remove function to discover if required tools are installed.
This commit is contained in:
@@ -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
|
||||||
@@ -21,7 +21,6 @@ from os import (
|
|||||||
set_inheritable,
|
set_inheritable,
|
||||||
write,
|
write,
|
||||||
)
|
)
|
||||||
from shutil import which
|
|
||||||
from subprocess import PIPE, Popen
|
from subprocess import PIPE, Popen
|
||||||
from sys import exit
|
from sys import exit
|
||||||
from typing import IO
|
from typing import IO
|
||||||
@@ -82,44 +81,6 @@ from tscut.tools.timeframe import (
|
|||||||
# Then finally, change the Private Codec Data in the final MKV.
|
# 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
|
@typechecked
|
||||||
def get_tesseract_supported_lang(tesseract_path:str) -> dict[Lang, str]|None:
|
def get_tesseract_supported_lang(tesseract_path:str) -> dict[Lang, str]|None:
|
||||||
|
|||||||
Reference in New Issue
Block a user