Changed the return values of get_cache_file_content to match the set file function bsed on code review

This commit is contained in:
Jules Lasne (jlasne - seluj78) 2020-10-12 08:50:36 +02:00
parent 150be9dabc
commit 892de5a568
2 changed files with 35 additions and 15 deletions

View File

@ -8,14 +8,22 @@ from typing import Tuple
def _get_cache_file_content(
path: str = ".potodo/cache.pickle",
) -> Tuple[Optional[datetime], Optional[dict]]:
) -> Optional[dict]:
try:
with open(path, "rb") as handle:
data = pickle.load(handle)
except FileNotFoundError:
return None, None
return None
else:
return data["dt_expiry"], data["data"]
content = data["data"]
dt_expiry = data["dt_expiry"]
if content:
if dt_expiry < datetime.utcnow():
return None
else:
return content
else:
return None
def _set_cache_content(obj, path: str = ".potodo/cache.pickle"):

View File

@ -131,25 +131,37 @@ def exec_potodo(
# Initialize the arguments
issue_reservations = get_issue_reservations(offline, hide_reserved, path)
update_cache = False
# update_cache = False
#
# if (
# no_cache
# or check_output(["git", "status", "--porcelain"], encoding="utf-8") != ""
# ):
# update_cache = True
# else:
# dt_expiry, content = _get_cache_file_content()
# if content:
# if dt_expiry < datetime.utcnow():
# update_cache = True
# else:
# update_cache = False
# po_files_and_dirs = content
# else:
# update_cache = True
#
# if update_cache:
# po_files_and_dirs = get_po_stats_from_repo(path, exclude)
# _set_cache_content(po_files_and_dirs) # update_cache = False
if (
no_cache
or check_output(["git", "status", "--porcelain"], encoding="utf-8") != ""
):
update_cache = True
po_files_and_dirs = None
else:
dt_expiry, content = _get_cache_file_content()
if content:
if dt_expiry < datetime.utcnow():
update_cache = True
else:
update_cache = False
po_files_and_dirs = content
else:
update_cache = True
po_files_and_dirs = _get_cache_file_content()
if update_cache:
if not po_files_and_dirs:
po_files_and_dirs = get_po_stats_from_repo(path, exclude)
_set_cache_content(po_files_and_dirs)