From 651d54b3ebf8b75eaba35bb1902c9042d1185a93 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Thu, 26 Sep 2024 14:11:46 +0200 Subject: [PATCH] Refactor file name handling and sequence padding logic. - Extracted file name from basename for processing. - Improved handling of sequence padding using regex pattern matching. - Enhanced file filtering based on the extracted file name. --- .../plugins/create/create_csv_ingest.py | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/client/ayon_traypublisher/plugins/create/create_csv_ingest.py b/client/ayon_traypublisher/plugins/create/create_csv_ingest.py index fd4dedd..494ce95 100644 --- a/client/ayon_traypublisher/plugins/create/create_csv_ingest.py +++ b/client/ayon_traypublisher/plugins/create/create_csv_ingest.py @@ -644,9 +644,21 @@ def _add_representation( # convert ### string in file name to %03d # this is for correct frame range validation # example: file.###.exr -> file.%03d.exr + file_name = basename.split(".")[0] if "#" in basename: padding = len(basename.split("#")) - 1 - basename = basename.replace("#" * padding, f"%0{padding}d") + seq_padding = f"%0{padding}d" + basename = basename.replace("#" * padding, seq_padding) + file_name = basename.split(seq_padding)[0] + is_sequence = True + if "%" in basename: + pattern = re.compile(r"%\d+d|%d") + padding = pattern.findall(basename) + if not padding: + raise CreatorError( + f"File sequence padding not found in '{basename}'." + ) + file_name = basename.split("%")[0] is_sequence = True # make absolute path to file @@ -662,8 +674,13 @@ def _add_representation( frame_end: Union[int, None] = None files: Union[str, List[str]] = basename if is_sequence: + # get only filtered files form dirname + files_from_dir = [ + file for file in os.listdir(dirname) + if file_name in file + ] # collect all data from dirname - cols, _ = clique.assemble(list(os.listdir(dirname))) + cols, _ = clique.assemble(files_from_dir) if not cols: raise CreatorError( f"No collections found in directory '{dirname}'."