From 0568a8061881300aefd6e3746e093ded4076a4b7 Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Tue, 1 Mar 2022 17:00:08 +0100 Subject: [PATCH] added 'is_file_executable' to check if file can be executed --- openpype/lib/vendor_bin_utils.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/openpype/lib/vendor_bin_utils.py b/openpype/lib/vendor_bin_utils.py index 5698ede16a..4be016f656 100644 --- a/openpype/lib/vendor_bin_utils.py +++ b/openpype/lib/vendor_bin_utils.py @@ -7,6 +7,25 @@ import subprocess log = logging.getLogger("Vendor utils") +def is_file_executable(filepath): + """Filepath lead to executable file. + + Args: + filepath(str): Full path to file. + """ + if not filepath: + return False + + if os.path.isfile(filepath): + if os.access(filepath, os.X_OK): + return True + + log.info( + "Filepath is not available for execution \"{}\"".format(filepath) + ) + return False + + def find_executable(executable): """Find full path to executable. @@ -24,7 +43,7 @@ def find_executable(executable): None: When the executable was not found. """ # Skip if passed path is file - if os.path.isfile(executable): + if is_file_executable(executable): return executable low_platform = platform.system().lower() @@ -45,7 +64,7 @@ def find_executable(executable): for ext in exts: variant = executable + ext - if os.path.isfile(variant): + if is_file_executable(variant): return variant variants.append(variant) @@ -62,7 +81,7 @@ def find_executable(executable): for path in paths: for variant in variants: filepath = os.path.abspath(os.path.join(path, variant)) - if os.path.isfile(filepath): + if is_file_executable(filepath): return filepath return None