Lookup a location of a file :param location: relative or absolute file location or a filename :param base_path: base path used for resolving relative paths or filenames :param exc: Flag, raise an exception if the file could not be found/does not exists :return: resolved path to
(location: str, base_path: Optional[str]=None, exc: bool=True)
| 155 | |
| 156 | |
| 157 | def get_file_location(location: str, base_path: Optional[str]=None, exc: bool=True) -> str: |
| 158 | """ |
| 159 | Lookup a location of a file |
| 160 | |
| 161 | :param location: relative or absolute file location or a filename |
| 162 | :param base_path: base path used for resolving relative paths or filenames |
| 163 | :param exc: Flag, raise an exception if the file could not be found/does not exists |
| 164 | :return: resolved path to the given file location |
| 165 | """ |
| 166 | if location.startswith("aura.data."): # Load file as a resource from aura package |
| 167 | return location |
| 168 | |
| 169 | if os.path.exists(location): |
| 170 | return location |
| 171 | |
| 172 | if base_path is not None: |
| 173 | pth = Path(base_path) / location |
| 174 | if pth.is_file(): |
| 175 | return str(pth) |
| 176 | else: |
| 177 | pth = location |
| 178 | |
| 179 | if exc: |
| 180 | # TODO: add location and base path directoly to the exception as variables for easy extraction |
| 181 | raise MissingFile(f"Can't find configuration file `{location}` using base path `{base_path}`") |
| 182 | else: |
| 183 | return pth |
| 184 | |
| 185 | |
| 186 | def get_file_content(location: str, base_path: Optional[str]=None) -> str: |
no test coverage detected