From 61916519f4ba376f32cde142cd450a50be9a3785 Mon Sep 17 00:00:00 2001 From: "Raryel C. Souza" Date: Tue, 12 Feb 2019 00:08:52 +0700 Subject: [PATCH] Add compatibility 'which function' with Windows. Check for program file in script folder before checking system path (local installation of ffmpeg) --- autosub/__init__.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/autosub/__init__.py b/autosub/__init__.py index f4adee137..5978b58d5 100644 --- a/autosub/__init__.py +++ b/autosub/__init__.py @@ -155,17 +155,26 @@ def is_exe(file_path): Checks whether a file is executable. """ return os.path.isfile(file_path) and os.access(file_path, os.X_OK) - + # necessary to run on Windows + if os.name == "nt": + program += ".exe" fpath, _ = os.path.split(program) if fpath: if is_exe(program): return program else: - for path in os.environ["PATH"].split(os.pathsep): - path = path.strip('"') - exe_file = os.path.join(path, program) - if is_exe(exe_file): - return exe_file + # looks for program file in the script execution folder + # before checking on system path + script_dir = os.getcwd() + local_program = os.path.join(script_dir, program) + if is_exe(local_program): + return local_program + else: + for path in os.environ["PATH"].split(os.pathsep): + path = path.strip('"') + exe_file = os.path.join(path, program) + if is_exe(exe_file): + return exe_file return None