forked from AFPy/potodo
34 lines
858 B
Python
34 lines
858 B
Python
import logging
|
|
import os
|
|
import pickle
|
|
from pathlib import Path
|
|
from typing import cast
|
|
from typing import Dict
|
|
|
|
from potodo.po_file import PoFileStats
|
|
|
|
|
|
def get_cache_file_content(
|
|
path: str = ".potodo/cache.pickle",
|
|
) -> Dict[Path, PoFileStats]:
|
|
logging.debug("Trying to load cache from %s", path)
|
|
try:
|
|
with open(path, "rb") as handle:
|
|
data = pickle.load(handle)
|
|
except FileNotFoundError:
|
|
logging.warning("No cache found")
|
|
return {}
|
|
else:
|
|
logging.debug("Found cache")
|
|
return cast(Dict[Path, PoFileStats], data)
|
|
|
|
|
|
def set_cache_content(
|
|
obj: Dict[Path, PoFileStats], path: str = ".potodo/cache.pickle"
|
|
) -> None:
|
|
os.makedirs(os.path.dirname(path), exist_ok=True)
|
|
|
|
with open(path, "wb") as handle:
|
|
pickle.dump(obj, handle)
|
|
logging.debug("Set cache to %s", path)
|