from enum import Enum import re import os def split_path(path: str) -> list: """ Splits given path into subdirectories. Parameters: path (str): Whole path. Returns: List: List of subdirectories. """ PATH_DELIMETER = os.path.sep split_path = path.split(PATH_DELIMETER) # remove empty values split_path = [i for i in split_path if i.strip()!=""] return split_path def get_path_components(asset_path: str) -> dict: """ Identifies important components of the given path using a hardcoded schema. Parameters: asset_path (str): The path to derive components from. Returns: dict: Name mapped components. """ regex_pattern = r"(?P/shows/(?P\S*?)/\S*?/(?P\S*?)/(?P\S*?)_v(?P\S*?)/(?P\S*?)/\S*?/(?P\S*?)_v(?P\d*)\D*?(?P\d*)\D*?\.(?P\w*)\Z)" pattern = re.compile(regex_pattern) match = pattern.match(asset_path) if(match is None): raise Exception("Regex pattern matching failed. This is likely due to one of your paths using the incorrect schema.") path_components = match.groupdict() return path_components class AnsiCodes(Enum): """ Ansi color codes for styling text. """ FORE_RED = "\033[31m" FORE_GREEN = "\033[32m" DEFAULT = "\033[0m"