MCPcopy Create free account
hub / github.com/ClangBuiltLinux/boot-utils / find_first_file

Function find_first_file

utils.py:76–106  ·  view source on GitHub ↗

Attempts to find the first option available in the list of files relative to a specified root folder. Parameters: relative_root (Path): A Path object containing the folder to search for files within. possible_files (list): A list of Paths t

(
    relative_root: Path,
    possible_files: Iterable[Path | str],
    required: bool = True,
)

Source from the content-addressed store, hash-verified

74
75
76def find_first_file(
77 relative_root: Path,
78 possible_files: Iterable[Path | str],
79 required: bool = True,
80) -> Path:
81 """
82 Attempts to find the first option available in the list of files relative
83 to a specified root folder.
84
85 Parameters:
86 relative_root (Path): A Path object containing the folder to search for
87 files within.
88 possible_files (list): A list of Paths that may be within the relative
89 root folder. They will be automatically appended
90 to relative_root.
91 required (bool): Whether or not the file is required, which determines
92 if not finding the file is an error.
93 Returns:
94 The full path to the first file found in the list. If none could be
95 found, an Exception is raised.
96 """
97 for possible_file in possible_files:
98 if (full_path := relative_root.joinpath(possible_file)).exists():
99 return full_path
100 if required:
101 files_str = "', '".join([str(elem) for elem in possible_files])
102 msg = f"No files from list ('{files_str}') could be found within '{relative_root}'!"
103 raise FileNotFoundError(
104 msg,
105 )
106 return UNINIT_PATH
107
108
109def get_full_kernel_path(kernel_location: Path | str, image: str, arch: str | None = None) -> Path:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected