from pathlib import Path
[docs]
class PathManager():
"""
Class to manage paths that will be used by the pipeline. It is used to create directories and check if they exist.
"""
def __init__(
self,
dataset_dir: str = None,
case_dir: str = None,
):
if dataset_dir:
if not isinstance(dataset_dir, str):
raise ValueError("dataset_dir must be a string")
if not dataset_dir:
raise ValueError("dataset_dir cannot be an empty string")
self.dataset_dir = Path(dataset_dir)
if not self.dataset_dir.exists() or not self.dataset_dir.is_dir():
raise ValueError(f"dataset_dir '{dataset_dir}' does not exist or is not a directory")
else:
self.dataset_dir = None
if case_dir:
if not isinstance(case_dir, str):
raise ValueError("case_dir must be a string")
if not case_dir:
raise ValueError("case_dir cannot be an empty string")
self.case_dir = Path(case_dir)
if not self.case_dir.exists() or not self.case_dir.is_dir():
self.create_directory(self.case_dir)
else:
self.case_dir = None
[docs]
@staticmethod
def create_directory(path: Path):
if not path.exists():
try:
path.mkdir(parents=True, exist_ok=True)
except Exception as e:
print(f"Error creating directory '{path}': {e}")
# else:
# pass
# print(f"Directory '{path}' already exists.")