corrlib/corrlib/tracker.py
Justus Kuhlmann 821bc14f4b
Some checks failed
Ruff / ruff (push) Waiting to run
Mypy / mypy (push) Failing after 1m8s
Pytest / pytest (3.12) (push) Successful in 49s
Pytest / pytest (3.13) (push) Has been cancelled
Pytest / pytest (3.14) (push) Has been cancelled
avoid looking for a tracker before config exists
2025-12-04 12:36:41 +01:00

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