add getter for cache_dir_name and rename db filename getter
Some checks failed
Mypy / mypy (push) Failing after 4s
Pytest / pytest (3.12) (push) Failing after 2s
Pytest / pytest (3.13) (push) Failing after 2s
Pytest / pytest (3.14) (push) Failing after 2s
Ruff / ruff (push) Failing after 2s

This commit is contained in:
Justus Kuhlmann 2026-02-20 09:44:22 +01:00
commit 6ea1827b99
Signed by: jkuhl
GPG key ID: 00ED992DD79B85A6

View file

@ -1,8 +1,7 @@
import os
import datalad.api as dl
import hashlib
from configparser import ConfigParser
from typing import Any
from typing import Any, Union
CONFIG_FILENAME = ".corrlib"
cached: bool = True
@ -77,16 +76,6 @@ def k2m(k: float) -> float:
return (1/(2*k))-4
def get_file(path: str, file: str) -> None:
if file == get_db_file(path):
print("Downloading database...")
else:
print("Downloading data...")
dl.get(os.path.join(path, file), dataset=path)
print("> downloaded file")
return
def record2name_key(record_path: str) -> tuple[str, str]:
"""
Convert a record to a pair of name and key.
@ -155,7 +144,7 @@ def set_config(path: str, section: str, option: str, value: Any) -> None:
return
def get_db_file(path: str) -> str:
def db_filename(path: str) -> str:
"""
Get the database file associated with the library at the given path.
@ -199,3 +188,28 @@ def cache_enabled(path: str) -> bool:
cached_str = config.get('core', 'cached', fallback='True')
cached_bool = cached_str == ('True')
return cached_bool
def cache_dir_name(path: str) -> Union[str, None]:
"""
Get the database file associated with the library at the given path.
Parameters
----------
path: str
The path of the library.
Returns
-------
db_file: str
The file holding the database.
"""
config_path = os.path.join(path, CONFIG_FILENAME)
config = ConfigParser()
if os.path.exists(config_path):
config.read(config_path)
if cache_enabled(path):
cache = config.get('paths', 'cache', fallback='.cache')
else:
cache = None
return cache