mirror of
https://github.com/Benexl/FastAnime.git
synced 2025-12-25 04:15:19 -08:00
feat(cli): add cache command to manage your fastanime cache dir
This commit is contained in:
@@ -14,6 +14,7 @@ commands = {
|
||||
"anilist": "anilist.anilist",
|
||||
"config": "config.config",
|
||||
"downloads": "downloads.downloads",
|
||||
"cache": "cache.cache",
|
||||
}
|
||||
|
||||
|
||||
|
||||
35
fastanime/cli/commands/cache.py
Normal file
35
fastanime/cli/commands/cache.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import click
|
||||
|
||||
|
||||
@click.command(help="Helper command to manage cache")
|
||||
@click.option("--clean", help="Clean the cache dir", is_flag=True)
|
||||
@click.option("--path", help="The path to the cache dir", is_flag=True)
|
||||
@click.option("--size", help="The size of the cache dir", is_flag=True)
|
||||
def cache(clean, path, size):
|
||||
from ...constants import APP_CACHE_DIR
|
||||
|
||||
if path:
|
||||
print(APP_CACHE_DIR)
|
||||
elif clean:
|
||||
import shutil
|
||||
|
||||
from rich.prompt import Confirm
|
||||
|
||||
if Confirm.ask(
|
||||
f"Are you sure you want to clean the following path: {APP_CACHE_DIR};(NOTE: !!The action is irreversible and will clean your cache!!)",
|
||||
default=False,
|
||||
):
|
||||
print("Cleaning...")
|
||||
shutil.rmtree(APP_CACHE_DIR)
|
||||
print("Successfully removed: ", APP_CACHE_DIR)
|
||||
elif size:
|
||||
import os
|
||||
|
||||
from ..utils.utils import sizeof_fmt
|
||||
|
||||
total_size = 0
|
||||
for dirpath, dirnames, filenames in os.walk(APP_CACHE_DIR):
|
||||
for f in filenames:
|
||||
fp = os.path.join(dirpath, f)
|
||||
total_size += os.path.getsize(fp)
|
||||
print("Total Size: ", sizeof_fmt(total_size))
|
||||
@@ -22,6 +22,14 @@ BG_GREEN = "\033[48;2;120;233;12;m"
|
||||
GREEN = "\033[38;2;45;24;45;m"
|
||||
|
||||
|
||||
def sizeof_fmt(num, suffix="B"):
|
||||
for unit in ("", "K", "M", "G", "T", "P", "E", "Z"):
|
||||
if abs(num) < 1024.0:
|
||||
return f"{num:3.1f}{unit}{suffix}"
|
||||
num /= 1024.0
|
||||
return f"{num:.1f}Yi{suffix}"
|
||||
|
||||
|
||||
def get_true_fg(string: str, r: int, g: int, b: int, bold=True) -> str:
|
||||
if bold:
|
||||
return f"{BOLD}\033[38;2;{r};{g};{b};m{string}{RESET}"
|
||||
|
||||
Reference in New Issue
Block a user