From 4e0ae38a123ce09343b288208075ae5d4c58cdd2 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 18 Nov 2020 19:33:24 +0100 Subject: [PATCH] get_ffmpeg_tool_path moved to ffmpeg utils --- pype/lib/__init__.py | 10 ++++++---- pype/lib/ffmpeg_utils.py | 25 ++++++++++++++++++++++++- pype/lib/path_tools.py | 22 ---------------------- 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/pype/lib/__init__.py b/pype/lib/__init__.py index a3a3d7225d..188dd68039 100644 --- a/pype/lib/__init__.py +++ b/pype/lib/__init__.py @@ -38,11 +38,13 @@ from .plugin_tools import filter_pyblish_plugins, source_hash from .path_tools import ( version_up, get_version_from_path, - get_last_version_from_path, - get_ffmpeg_tool_path + get_last_version_from_path ) -from .ffmpeg_utils import ffprobe_streams +from .ffmpeg_utils import ( + get_ffmpeg_tool_path, + ffprobe_streams +) __all__ = [ "get_avalon_database", @@ -74,9 +76,9 @@ __all__ = [ "version_up", "get_version_from_path", "get_last_version_from_path", - "get_ffmpeg_tool_path", "ffprobe_streams", + "get_ffmpeg_tool_path", "source_hash", "_subprocess" diff --git a/pype/lib/ffmpeg_utils.py b/pype/lib/ffmpeg_utils.py index 0096fd13aa..ba9f24c5d7 100644 --- a/pype/lib/ffmpeg_utils.py +++ b/pype/lib/ffmpeg_utils.py @@ -1,12 +1,35 @@ +import os import logging import json import subprocess -from . import get_ffmpeg_tool_path +from . import get_paths_from_environ log = logging.getLogger("FFmpeg utils") +def get_ffmpeg_tool_path(tool="ffmpeg"): + """Find path to ffmpeg tool in FFMPEG_PATH paths. + + Function looks for tool in paths set in FFMPEG_PATH environment. If tool + exists then returns it's full path. + + Args: + tool (string): tool name + + Returns: + (str): tool name itself when tool path was not found. (FFmpeg path + may be set in PATH environment variable) + """ + dir_paths = get_paths_from_environ("FFMPEG_PATH") + for dir_path in dir_paths: + for file_name in os.listdir(dir_path): + base, _ext = os.path.splitext(file_name) + if base.lower() == tool.lower(): + return os.path.join(dir_path, tool) + return tool + + def ffprobe_streams(path_to_file, logger=None): """Load streams from entered filepath via ffprobe. diff --git a/pype/lib/path_tools.py b/pype/lib/path_tools.py index a0da0c2190..e1dd1e7f10 100644 --- a/pype/lib/path_tools.py +++ b/pype/lib/path_tools.py @@ -5,28 +5,6 @@ import logging log = logging.getLogger(__name__) -def get_ffmpeg_tool_path(tool="ffmpeg"): - """Find path to ffmpeg tool in FFMPEG_PATH paths. - - Function looks for tool in paths set in FFMPEG_PATH environment. If tool - exists then returns it's full path. - - Args: - tool (string): tool name - - Returns: - (str): tool name itself when tool path was not found. (FFmpeg path - may be set in PATH environment variable) - """ - dir_paths = get_paths_from_environ("FFMPEG_PATH") - for dir_path in dir_paths: - for file_name in os.listdir(dir_path): - base, _ext = os.path.splitext(file_name) - if base.lower() == tool.lower(): - return os.path.join(dir_path, tool) - return tool - - def _rreplace(s, a, b, n=1): """Replace a with b in string s from right side n times.""" return b.join(s.rsplit(a, n))