1010from pathlib import Path
1111
1212from .config import get_cache_dir
13+ from .utils import inform
14+
15+ _log = logging .getLogger (__name__ )
1316
1417
1518# used if needed to preserve board path structure in the cache
@@ -65,7 +68,7 @@ def _make_local_details(self, path):
6568 # note that this is called in ._open(), at the point it's known the file
6669 # will be cached
6770 fn = super ()._make_local_details (path )
68- logging .info (f"cache file: { fn } " )
71+ _log .info (f"cache file: { fn } " )
6972 Path (fn ).parent .mkdir (parents = True , exist_ok = True )
7073
7174 return fn
@@ -200,7 +203,7 @@ def prune(self, days=30):
200203 for path in to_prune :
201204 delete_version (to_prune )
202205
203- logging .info ("Skipping cache deletion" )
206+ _log .info ("Skipping cache deletion" )
204207
205208
206209def delete_version (path : "str | Path" ):
@@ -213,10 +216,28 @@ def disk_usage(path):
213216
214217
215218def prompt_cache_prune (to_prune , size ) -> bool :
216- logging .info (f"Pruning items: { to_prune } " )
219+ _log .info (f"Pruning items: { to_prune } " )
217220 human_size = humanize .naturalsize (size , binary = True )
218- resp = input (f"Delete { len (to_prune )} pin versions, freeing { human_size } ?" )
219- return resp == "yes"
221+ resp = input (
222+ f"Delete { len (to_prune )} pin versions, freeing { human_size } ?"
223+ "\n 1: Yes"
224+ "\n 2: No"
225+ "\n \n Selection: "
226+ )
227+ return resp == "1"
228+
229+
230+ def cache_info ():
231+ cache_root = get_cache_dir ()
232+
233+ cache_boards = list (Path (cache_root ).glob ("*" ))
234+
235+ print (f"Cache info: { cache_root } " )
236+ for p_board in cache_boards :
237+ du = disk_usage (p_board )
238+ human_size = humanize .naturalsize (du , binary = True )
239+ rel_path = p_board .relative_to (cache_root )
240+ print (f"* { rel_path } : { human_size } " )
220241
221242
222243def cache_prune (days = 30 , cache_root = None , prompt = True ):
@@ -230,32 +251,21 @@ def cache_prune(days=30, cache_root=None, prompt=True):
230251
231252 size = sum (map (disk_usage , final_delete ))
232253
254+ if not final_delete :
255+ inform (_log , "No stale pins found" )
256+
233257 if prompt :
234258 confirmed = prompt_cache_prune (final_delete , size )
235259 else :
236260 confirmed = True
261+
237262 if confirmed :
263+ inform (_log , "Deleting pins from cache." )
238264 for p in final_delete :
239265 delete_version (p )
266+ else :
267+ inform (_log , "Skipping deletion of pins from cache." )
240268
241269
242- # def prune_files(days = 30, path = None):
243- # if path is None:
244- # for p_cache in Path(get_cache_dir()).glob("*"):
245- # return prune_files(days=days, path=str(p_cache.absolute()))
246- #
247- # expiry_time_sec = days * 60 * 60 * 24
248- # fs_cache = PinsCache(
249- # target_protocol=None,
250- # cache_storage=path,
251- # check_files=True,
252- # expiry_time=expiry_time_sec
253- # )
254- #
255- # # note that fsspec considers only the last entry in cached_files deletable
256- # for hash_path, entry in fs_cache.cached_files[-1].items():
257- # if time.time() - detail["time"] > self.expiry:
258- # fs_cache.pop_from_cache(entry["original"])
259-
260270# TODO: swap to use entrypoint
261271register_implementation ("pinscache" , PinsCache )
0 commit comments