46 lines
1.2 KiB
Python
46 lines
1.2 KiB
Python
import os
|
|
from configparser import ConfigParser
|
|
from .trackers import datalad as dl
|
|
from typing import Optional
|
|
|
|
|
|
def get_tracker(path: str) -> str:
|
|
config_path = os.path.join(path, '.corrlib')
|
|
config = ConfigParser()
|
|
if os.path.exists(config_path):
|
|
config.read(config_path)
|
|
else:
|
|
raise FileNotFoundError(f"No config file found in {path}.")
|
|
tracker = config.get('core', 'tracker', fallback='datalad')
|
|
return tracker
|
|
|
|
|
|
def get(path: str, file: str) -> None:
|
|
tracker = get_tracker(path)
|
|
if tracker == 'datalad':
|
|
dl.get(path, file)
|
|
elif tracker == 'None':
|
|
pass
|
|
else:
|
|
raise ValueError(f"Tracker {tracker} is not supported.")
|
|
return
|
|
|
|
|
|
def save(path: str, message: str, files: Optional[list[str]]=None) -> None:
|
|
tracker = get_tracker(path)
|
|
if tracker == 'datalad':
|
|
dl.save(path, message, files)
|
|
elif tracker == 'None':
|
|
pass
|
|
else:
|
|
raise ValueError(f"Tracker {tracker} is not supported.")
|
|
|
|
|
|
def init(path: str, tracker: str='datalad') -> None:
|
|
if tracker == 'datalad':
|
|
dl.create(path)
|
|
elif tracker == 'None':
|
|
os.makedirs(path, exist_ok=True)
|
|
else:
|
|
raise ValueError(f"Tracker {tracker} is not supported.")
|
|
return
|