diff --git a/corrlib/cli.py b/corrlib/cli.py index e703857..ca2acb2 100644 --- a/corrlib/cli.py +++ b/corrlib/cli.py @@ -6,6 +6,7 @@ from .toml import import_tomls, update_project, reimport_project from .find import find_record, list_projects from .tools import str2list from .main import update_aliases +from .meas_io import drop_cache as mio_drop_cache import os app = typer.Typer() @@ -157,6 +158,21 @@ def init( return +@app.command() +def drop_cache( + path: str = typer.Option( + str('./corrlib'), + "--dataset", + "-d", + ), +) -> None: + """ + Drop the currect cache directory of the dataset. + """ + mio_drop_cache(path) + return + + @app.callback() def main( version: Optional[bool] = typer.Option( diff --git a/corrlib/meas_io.py b/corrlib/meas_io.py index 9a3806b..1a06dac 100644 --- a/corrlib/meas_io.py +++ b/corrlib/meas_io.py @@ -8,6 +8,7 @@ from typing import Union from pyerrors import Obs, Corr, dump_object, load_object from hashlib import sha256 from .tools import cached +import shutil def write_measurement(path, ensemble, measurement, uuid, code, parameter_file=None): @@ -194,3 +195,8 @@ def drop_record(path: str, meas_path: str): return else: raise ValueError("This measurement does not exist as a file!") + +def drop_cache(path: str): + cache_dir = os.path.join(path, ".cache") + for f in os.listdir(cache_dir): + shutil.rmtree(os.path.join(cache_dir, f))