Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor file name handling and sequence padding logic. #26

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions client/ayon_traypublisher/plugins/create/create_csv_ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be elif? Because after the first if the % will be in the basename and will then ALSO trigger that logic. Not sure if intentional?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree this will run if the filename had # in filename, which is not needed, or?

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]
jakubjezek001 marked this conversation as resolved.
Show resolved Hide resolved
is_sequence = True

# make absolute path to file
Expand All @@ -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}'."
Expand Down