Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General: Fix python 2 compatibility of ffmpeg and oiio tools discovery #4011

Merged
merged 1 commit into from
Oct 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 24 additions & 24 deletions openpype/lib/vendor_bin_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,28 @@ def find_tool_in_custom_paths(paths, tool, validation_func=None):
return None


def _check_args_returncode(args):
try:
# Python 2 compatibility where DEVNULL is not available
if hasattr(subprocess, "DEVNULL"):
proc = subprocess.Popen(
args,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
proc.wait()
else:
with open(os.devnull, "w") as devnull:
proc = subprocess.Popen(
args, stdout=devnull, stderr=devnull,
)
proc.wait()

except Exception:
return False
return proc.returncode == 0


def _oiio_executable_validation(filepath):
"""Validate oiio tool executable if can be executed.

Expand Down Expand Up @@ -223,18 +245,7 @@ def _oiio_executable_validation(filepath):
if not filepath:
return False

try:
proc = subprocess.Popen(
[filepath, "--help"],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
proc.wait()
return proc.returncode == 0

except Exception:
pass
return False
return _check_args_returncode([filepath, "--help"])


def get_oiio_tools_path(tool="oiiotool"):
Expand Down Expand Up @@ -302,18 +313,7 @@ def _ffmpeg_executable_validation(filepath):
if not filepath:
return False

try:
proc = subprocess.Popen(
[filepath, "-version"],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
proc.wait()
return proc.returncode == 0

except Exception:
pass
return False
return _check_args_returncode([filepath, "-version"])


def get_ffmpeg_tool_path(tool="ffmpeg"):
Expand Down