refactor: separate code into separate files, add docstrings

This commit is contained in:
parker
2025-10-05 16:51:03 +01:00
parent 0597be32df
commit cf2c1fb070
3 changed files with 258 additions and 172 deletions

View File

@@ -0,0 +1,53 @@
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<full_path>/shows/(?P<project_name>\S*?)/\S*?/(?P<asset_type>\S*?)/(?P<asset_name>\S*?)_v(?P<asset_version>\S*?)/(?P<task>\S*?)/\S*?/(?P<file_name>\S*?)_v(?P<file_version>\d*)\D*?(?P<frame_number>\d*)\D*?\.(?P<file_extension>\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"