-
Notifications
You must be signed in to change notification settings - Fork 128
Expand file tree
/
Copy pathclear_sharrow_cache.py
More file actions
56 lines (46 loc) · 1.62 KB
/
clear_sharrow_cache.py
File metadata and controls
56 lines (46 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env -S uv run --script --no-project
#
# /// script
# requires-python = ">=3.10,<3.12"
# dependencies = [
# "platformdirs",
# ]
# ///
from __future__ import annotations
import shutil
from datetime import datetime
from pathlib import Path
import platformdirs
def clear_sharrow_cache(archive: bool = True):
"""Disable all files in the sharrow cache directory.
Parameters
----------
archive : bool, optional
If True, move the files to an 'archive' subdirectory instead of deleting them,
by default True.
"""
main_dir = Path(platformdirs.user_cache_dir(appname="ActivitySim"))
print(f"Scanning ActivitySim cache directory for sharrow files: {main_dir}")
sharrow_cache_dirs = main_dir.glob("sharrow-*-numba-*")
timestamp = datetime.now().strftime("%Y%m%d-%H%M%S")
# define the archive path if archiving is enabled
if archive:
archive_path = Path(
platformdirs.user_cache_dir(appname="ActivitySim")
).joinpath(f"archive-{timestamp}")
else:
archive_path = None
for sharrow_cache_dir in sharrow_cache_dirs:
if sharrow_cache_dir.is_dir():
print(f"Clearing sharrow cache directory: {sharrow_cache_dir}")
if archive:
archive_path.mkdir(parents=True, exist_ok=True)
shutil.move(
str(sharrow_cache_dir), str(archive_path / sharrow_cache_dir.name)
)
else:
shutil.rmtree(str(sharrow_cache_dir))
else:
print("No sharrow cache directories found.")
if __name__ == "__main__":
clear_sharrow_cache(archive=True)