refactor io

This commit is contained in:
Justus Kuhlmann 2025-11-20 17:13:17 +01:00
commit 4f3e78177e
Signed by: jkuhl
GPG key ID: 00ED992DD79B85A6
3 changed files with 46 additions and 24 deletions

33
corrlib/cache_io.py Normal file
View file

@ -0,0 +1,33 @@
from typing import Union, Optional
import os
import shutil
def drop_cache_files(path: str, fs: Optional[list[str]]=None):
cache_dir = os.path.join(path, ".cache")
if fs is None:
fs = os.listdir(cache_dir)
for f in fs:
shutil.rmtree(os.path.join(cache_dir, f))
def cache_dir(path, file):
cache_path_list = [path]
cache_path_list.append(".cache")
cache_path_list.extend(file.split("/")[1:])
cache_path = "/".join(cache_path_list)
return cache_path
def cache_path(path, file, hash, key):
cache_path = os.path.join(cache_dir(path, file), hash, key)
return cache_path
def is_in_cache(path, record, hash):
if os.file.exists(cache_path(path, file, hash, key)):
return True
else:
return False