Few small different syntex fixes and so on

This commit is contained in:
N0\A
2025-11-10 11:32:33 +01:00
parent e38b1b3052
commit d4ff7feb17
6 changed files with 757 additions and 408 deletions

View File

@@ -1,8 +1,8 @@
import fnmatch
import os
import shutil
import subprocess
import os
import platform
import fnmatch
def _find_native(pattern: str, root: str):
"""Native Python implementation of file search using os.walk."""
@@ -12,14 +12,17 @@ def _find_native(pattern: str, root: str):
results.append(os.path.join(dirpath, filename))
return results
def find(pattern: str, root: str='/'):
def find(pattern: str, root: str = "/"):
path = os.path.expanduser(root)
if shutil.which('fd') is None:
if shutil.which("fd") is None:
return _find_native(f"*{pattern}*", path)
else:
try:
out = subprocess.check_output(['fd', pattern, path], text=True, errors='ignore')
out = subprocess.check_output(
["fd", pattern, path], text=True, errors="ignore"
)
return out.splitlines()
except subprocess.CalledProcessError:
return []
return []