mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2025-10-23 15:11:08 +00:00
Update binaries.py
Refactor code to search for binaries either in root of binary folder or in a subfolder named after the binary.
This commit is contained in:
@@ -10,23 +10,23 @@ __shaka_platform = {"win32": "win", "darwin": "osx"}.get(sys.platform, sys.platf
|
|||||||
|
|
||||||
def find(*names: str) -> Optional[Path]:
|
def find(*names: str) -> Optional[Path]:
|
||||||
"""Find the path of the first found binary name."""
|
"""Find the path of the first found binary name."""
|
||||||
# Get the directory containing this file to find the local binaries folder
|
current_dir = Path(__file__).resolve().parent.parent
|
||||||
current_dir = Path(__file__).parent.parent
|
|
||||||
local_binaries_dir = current_dir / "binaries"
|
local_binaries_dir = current_dir / "binaries"
|
||||||
|
|
||||||
for name in names:
|
ext = ".exe" if sys.platform == "win32" else ""
|
||||||
# First check local binaries folder
|
|
||||||
if local_binaries_dir.exists():
|
|
||||||
# On Windows, check for .exe extension first
|
|
||||||
if sys.platform == "win32":
|
|
||||||
local_path_exe = local_binaries_dir / f"{name}" / f"{name}.exe"
|
|
||||||
if local_path_exe.is_file():
|
|
||||||
return local_path_exe
|
|
||||||
|
|
||||||
# Check for exact name match with executable bit on Unix-like systems
|
for name in names:
|
||||||
local_path = local_binaries_dir / f"{name}" / f"{name}"
|
if local_binaries_dir.exists():
|
||||||
if local_path.is_file() and local_path.stat().st_mode & 0o111: # Check if executable
|
candidate_paths = [
|
||||||
return local_path
|
local_binaries_dir / f"{name}{ext}",
|
||||||
|
local_binaries_dir / name / f"{name}{ext}"
|
||||||
|
]
|
||||||
|
|
||||||
|
for path in candidate_paths:
|
||||||
|
if path.is_file():
|
||||||
|
# On Unix-like systems, check if file is executable
|
||||||
|
if sys.platform == "win32" or (path.stat().st_mode & 0o111):
|
||||||
|
return path
|
||||||
|
|
||||||
# Fall back to system PATH
|
# Fall back to system PATH
|
||||||
path = shutil.which(name)
|
path = shutil.which(name)
|
||||||
|
|||||||
Reference in New Issue
Block a user