refactor: separate code into separate files, add docstrings
This commit is contained in:
53
src/bb_asset_validation/utils.py
Normal file
53
src/bb_asset_validation/utils.py
Normal 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"
|
||||
Reference in New Issue
Block a user