All checks were successful
Build and Release .deb / build-deb (push) Successful in 21s
- Add clear_cache() called once in on_mount - ensure_cache_dir() no longer deletes existing files - This fixes the issue where only the last target's cache survived - Add widget.refresh() calls to force UI updates
47 lines
1.2 KiB
Python
47 lines
1.2 KiB
Python
import json
|
|
import os
|
|
import shutil
|
|
from datetime import datetime
|
|
from typing import Any
|
|
|
|
CACHE_DIR = "/tmp/full-updater-cache"
|
|
|
|
|
|
def clear_cache() -> None:
|
|
if os.path.exists(CACHE_DIR):
|
|
shutil.rmtree(CACHE_DIR)
|
|
|
|
|
|
def ensure_cache_dir() -> None:
|
|
os.makedirs(CACHE_DIR, exist_ok=True)
|
|
|
|
|
|
def write_cache(target_id: str, data: dict[str, Any]) -> None:
|
|
ensure_cache_dir()
|
|
path = os.path.join(CACHE_DIR, f"{target_id}.json")
|
|
with open(path, "w", encoding="utf-8") as f:
|
|
json.dump(data, f, indent=2)
|
|
|
|
|
|
def read_cache(target_id: str) -> dict[str, Any] | None:
|
|
path = os.path.join(CACHE_DIR, f"{target_id}.json")
|
|
if not os.path.exists(path):
|
|
return None
|
|
with open(path, "r", encoding="utf-8") as f:
|
|
return json.load(f)
|
|
|
|
|
|
def get_cache_timestamp(target_id: str) -> str:
|
|
path = os.path.join(CACHE_DIR, f"{target_id}.json")
|
|
if not os.path.exists(path):
|
|
return ""
|
|
try:
|
|
with open(path, "r", encoding="utf-8") as f:
|
|
data = json.load(f)
|
|
ts = data.get("timestamp", "")
|
|
if ts:
|
|
dt = datetime.fromisoformat(ts)
|
|
return dt.strftime("%H:%M:%S")
|
|
except Exception:
|
|
pass
|
|
return ""
|