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,
)
| 74 | |
| 75 | |
| 76 | def 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 | |
| 109 | def get_full_kernel_path(kernel_location: Path | str, image: str, arch: str | None = None) -> Path: |
nothing calls this directly
no outgoing calls
no test coverage detected