diff -r f0fd0c1592e2 -r ca9ece290f71 src/eric7/SystemUtilities/FileSystemUtilities.py --- a/src/eric7/SystemUtilities/FileSystemUtilities.py Thu Jun 20 15:18:30 2024 +0200 +++ b/src/eric7/SystemUtilities/FileSystemUtilities.py Fri Jun 21 19:41:16 2024 +0200 @@ -12,6 +12,7 @@ import fnmatch import os import pathlib +import shutil import subprocess # secok from eric7.SystemUtilities import OSUtilities @@ -106,20 +107,7 @@ search path defined by the PATH environment variable. @rtype bool """ - if os.path.isabs(file): - return os.access(file, os.X_OK) - - if os.path.exists(os.path.join(os.curdir, file)): - return os.access(os.path.join(os.curdir, file), os.X_OK) - - path = OSUtilities.getEnvironmentEntry("PATH") - - # environment variable not defined - if path is None: - return False - - dirs = path.split(os.pathsep) - return any(os.access(os.path.join(directory, file), os.X_OK) for directory in dirs) + return bool(shutil.which(file)) def startsWithPath(path, start): @@ -201,29 +189,8 @@ empty string otherwise. @rtype str """ - if os.path.isabs(file): - if os.access(file, os.X_OK): - return file - else: - return "" - - cur_path = os.path.join(os.curdir, file) - if os.path.exists(cur_path) and os.access(cur_path, os.X_OK): - return cur_path - - path = os.getenv("PATH") - - # environment variable not defined - if path is None: - return "" - - dirs = path.split(os.pathsep) - for directory in dirs: - exe = os.path.join(directory, file) - if os.access(exe, os.X_OK): - return exe - - return "" + exe = shutil.which(file) + return exe if bool(exe) else "" def getExecutablePaths(file): @@ -262,51 +229,6 @@ return paths -def getWindowsExecutablePath(file): - """ - Function to build the full path of an executable file from the environment - on Windows platforms. - - First an executable with the extension .exe is searched for, thereafter - such with the extensions .cmd or .bat and finally the given file name as - is. The first match is returned. - - @param file filename of the executable to check - @type str - @return full executable name, if the executable file is accessible via the - executable search path defined by the PATH environment variable, or an - empty string otherwise. - @rtype str - """ - if os.path.isabs(file): - if os.access(file, os.X_OK): - return file - else: - return "" - - filenames = [file + ".exe", file + ".cmd", file + ".bat", file] - - for filename in filenames: - cur_path = os.path.join(os.curdir, filename) - if os.path.exists(cur_path) and os.access(cur_path, os.X_OK): - return os.path.abspath(cur_path) - - path = os.getenv("PATH") - - # environment variable not defined - if path is None: - return "" - - dirs = path.split(os.pathsep) - for directory in dirs: - for filename in filenames: - exe = os.path.join(directory, filename) - if os.access(exe, os.X_OK): - return exe - - return "" - - def isExecutable(exe): """ Function to check, if a file is executable.