add-resume #12

Merged
dan merged 7 commits from add-resume into dev 2023-12-07 19:38:19 +01:00
2 changed files with 10 additions and 4 deletions
Showing only changes of commit 064e4dae2d - Show all commits

View file

@ -29,6 +29,8 @@ def run():
session_id = "test-" + get_datetime_string()
if args.resume:
latest_session_id = DirManager.get_latest_session_id(args.output_dir)
if latest_session_id:
session_id = DirManager.get_latest_session_id(args.output_dir)
# ------------------------------- setup logging ------------------------------ #

View file

@ -1,4 +1,5 @@
from pathlib import Path
from typing import Optional
from dotenv import dotenv_values
@ -78,8 +79,11 @@ class DirManager:
return config
@staticmethod
def get_latest_session_id(output_dir: Path) -> str:
def get_latest_session_id(output_dir: Path) -> Optional[str]:
"""returns the name of the newest dir inside of output_dir"""
all_dirs = [d for d in output_dir.iterdir() if d.is_dir()]
if all_dirs:
newest_dir: Path = max(all_dirs, key=lambda x: x.stat().st_ctime)
return newest_dir.name
else:
return None