# filesystem_utils

Python API: `modelconverter.utils.filesystem_utils`

Resolution of the local and remote paths modelconverter reads.

Models, configs and calibration data may be given either as local paths or as URLs into bucket storage. The helpers here download
the remote ones, upload results back, and resolve relative local paths against the directory of the active config file and the
shared root (the cache directory inside the container, the working directory on the host).

## Functions

### download_from_remote

```python
def download_from_remote(url: str, dest: PathType, max_files: int = -1) -> Path:
```

Download file(s) from remote bucket storage.

It could be a single file, an entire directory, or `max_files` within a directory.

Parameters

 * `url` (`str`): URL of the file or directory to download.
 * `dest` (`PathType`): Local directory to download into.
 * `max_files` (`int`): Maximum number of files to download from a directory. Negative means no limit.

Returns

 * `Path`: Path to the downloaded file or directory.

### get_input_bases

```python
def get_input_bases() -> list[Path]:
```

Return the base directories tried, in order, for a relative local path that does not exist as-is.

The active config's directory comes first, then the default root. The default has to stay as a fallback: a config downloaded from
remote storage lands in the cache, so the paths it references relative to the shared root would otherwise stop resolving.

### get_protocol

```python
def get_protocol(url: str) -> str:
```

Return LuxonisFileSystem protocol.

### resolve_input_path

```python
def resolve_input_path(string: str) -> Path | None:
```

Resolve a relative local path against the input bases.

Returns `None` if the path exists under none of them.

### resolve_path

```python
def resolve_path(string: str, dest: Path) -> Path:
```

Download the file from remote or return the path otherwise.

### set_input_base

```python
def set_input_base(base: Path | None):
```

Set the base directory for resolving relative local paths.

Pass `None` to reset to the default.

### upload_to_remote

```python
def upload_to_remote(local_path: PathType, url: str, put_file_plugin: str | None = None):
```

Upload a file or a directory to remote bucket storage.
