From 6ea1827b99fbb250aa9680c575094a9533d8eff0 Mon Sep 17 00:00:00 2001 From: Justus Kuhlmann Date: Fri, 20 Feb 2026 09:44:22 +0100 Subject: [PATCH] add getter for cache_dir_name and rename db filename getter --- corrlib/tools.py | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/corrlib/tools.py b/corrlib/tools.py index 6dc6aec..e46ce0a 100644 --- a/corrlib/tools.py +++ b/corrlib/tools.py @@ -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