refactor io
This commit is contained in:
parent
91c7a9d95d
commit
4f3e78177e
3 changed files with 46 additions and 24 deletions
33
corrlib/cache_io.py
Normal file
33
corrlib/cache_io.py
Normal 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
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue