add getter for cache_dir_name and rename db filename getter
This commit is contained in:
parent
3d91509ab6
commit
6ea1827b99
1 changed files with 27 additions and 13 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue