Auto-detect backend to use

This commit is contained in:
Midgard 2022-09-18 04:13:34 +02:00
parent 72504309cc
commit 903ae85abc
Signed by untrusted user who does not match committer: midgard
GPG Key ID: 511C112F1331BBB4
1 changed files with 11 additions and 4 deletions

View File

@ -3,6 +3,7 @@
import sys
import os
import subprocess
import shutil
from glob import glob
import re
@ -78,28 +79,34 @@ def list_from_print0(data):
]
FIND_CMD = shutil.which("find")
def find(query, paths, depth=None):
depth_args = ["-mindepth", f"{depth}", "-maxdepth", f"{depth}"] if depth is not None else []
proc = subprocess.run(
["find", *paths, *depth_args, "-iname", f"*{query}*.ebuild", "-print0"],
[FIND_CMD, *paths, *depth_args, "-iname", f"*{query}*.ebuild", "-print0"],
check=True, stdout=subprocess.PIPE
)
return list_from_print0(proc.stdout)
FD_CMD = shutil.which("fd")
def fd(query, paths, depth):
depth_args = [f"--exact-depth={depth}"] if depth is not None else []
proc = subprocess.run(
["fd", *depth_args, "--print0", "--extension=ebuild", "--", query, *paths],
[FD_CMD, *depth_args, "--print0", "--extension=ebuild", "--", query, *paths],
check=True, stdout=subprocess.PIPE
)
return list_from_print0(proc.stdout)
# search_backend = find
search_backend = fd
if FD_CMD is not None:
search_backend = fd
elif FIND_CMD is not None:
search_backend = find
else:
raise Exception("Neither `fd` nor `find` found in PATH")
# Ebuild reading