import logging
import sys
from pathlib import Path
logger = logging.getLogger(__name__)
[docs]
class PathValidator:
"""This class provides methods to validate paths."""
[docs]
@staticmethod
def validate_path(target_path: str) -> str:
"""Validates the given paths.
:param target_path: The target path to validate.
:return: The absolute path for target.
"""
if target_path is not None:
target_path = Path(target_path).resolve()
try:
target_path.mkdir(parents=True, exist_ok=True)
except OSError as e:
logger.error(
"The path is not a valid path: %s, Error: %s.", target_path, e
)
sys.exit(1)
return target_path
else:
logger.error("Please specify a target path.")
sys.exit(1)