move create_file_list to Houdini's lib

This commit is contained in:
MustafaJafar 2024-03-04 22:41:35 +02:00
parent 746819ef51
commit 607a2666c3
2 changed files with 37 additions and 37 deletions

View file

@ -1054,3 +1054,39 @@ def add_self_publish_button(node):
template = node.parmTemplateGroup()
template.insertBefore((0,), button_parm)
node.setParmTemplateGroup(template)
def create_file_list(match, start_frame, end_frame):
"""Collect files based on frame range and `regex.match`
Args:
match(re.match): match object
start_frame(int): start of the animation
end_frame(int): end of the animation
Returns:
list
"""
# Get the padding length
frame = match.group(1)
padding = len(frame)
# Get the parts of the filename surrounding the frame number,
# so we can put our own frame numbers in.
span = match.span(1)
prefix = match.string[: span[0]]
suffix = match.string[span[1]:]
# Generate filenames for all frames
result = []
for i in range(start_frame, end_frame + 1):
# Format frame number by the padding amount
str_frame = "{number:0{width}d}".format(number=i, width=padding)
file_name = prefix + str_frame + suffix
result.append(file_name)
return result

View file

@ -54,46 +54,10 @@ class CollectFrames(pyblish.api.InstancePlugin):
# Check if frames are bigger than 1 (file collection)
# override the result
if end_frame - start_frame > 0:
result = self.create_file_list(
result = lib.create_file_list(
match, int(start_frame), int(end_frame)
)
# todo: `frames` currently conflicts with "explicit frames" for a
# for a custom frame list. So this should be refactored.
instance.data.update({"frames": result})
@staticmethod
def create_file_list(match, start_frame, end_frame):
"""Collect files based on frame range and `regex.match`
Args:
match(re.match): match object
start_frame(int): start of the animation
end_frame(int): end of the animation
Returns:
list
"""
# Get the padding length
frame = match.group(1)
padding = len(frame)
# Get the parts of the filename surrounding the frame number,
# so we can put our own frame numbers in.
span = match.span(1)
prefix = match.string[: span[0]]
suffix = match.string[span[1]:]
# Generate filenames for all frames
result = []
for i in range(start_frame, end_frame + 1):
# Format frame number by the padding amount
str_frame = "{number:0{width}d}".format(number=i, width=padding)
file_name = prefix + str_frame + suffix
result.append(file_name)
return result