create_base_filename.py 679 B

123456789101112131415161718192021222324
  1. import os
  2. from typing import Optional
  3. def _create_base_filename(
  4. title: Optional[str], output_path: str, model: str, date: str
  5. ) -> str:
  6. base = f"{date}__{model}__{replace_path_sep(title)}"
  7. return os.path.join(output_path, base, base)
  8. def create_base_filename(
  9. title: Optional[str], output_path: str, model: str, date: str
  10. ) -> str:
  11. base_filename = _create_base_filename(title, output_path, model, date)
  12. base_directory = os.path.dirname(base_filename)
  13. os.makedirs(base_directory, exist_ok=True)
  14. return base_filename
  15. def replace_path_sep(title: Optional[str]) -> str:
  16. return "None" if title is None else title.replace(os.path.sep, "_")