-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathfetcher.py
More file actions
38 lines (28 loc) · 965 Bytes
/
fetcher.py
File metadata and controls
38 lines (28 loc) · 965 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""Helpers for grabbing from remote repositories."""
from pathlib import Path
from typing import Literal
from neuromaps_prime.remote import OSFStorage
def id_storage(uri: str) -> Literal["osf"] | None:
"""Identify the storage type.
Args:
uri: Remote URI to fetch data from
Returns:
String indicating type of storage (one of 'osf')
"""
if "osf.io" in uri:
return "osf"
return None
def download_and_validate(uri: str, dest: str | Path) -> None:
"""Download and validate the file.
Args:
uri: Remote URI to fetch data from
dest: Output file path name
token: Optional token to use for remote storage
Raises:
ValueError: if storage cannot be identified from provided URI
"""
match id_storage(uri):
case "osf":
OSFStorage().download(uri, Path(dest))
case _:
raise ValueError(f"Could not identify storage from uri: {uri}")