Skip to content

Commit

Permalink
move houdini specific code to a method
Browse files Browse the repository at this point in the history
  • Loading branch information
MustafaJafar committed Sep 2, 2024
1 parent 62679b2 commit 6121964
Showing 1 changed file with 32 additions and 22 deletions.
54 changes: 32 additions & 22 deletions client/ayon_houdini/plugins/publish/extract_last_published.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,7 @@ def process(self, instance):
"last version published files.")
return

expected_filenames = []
staging_dir = instance.data.get("stagingDir")
expectedFiles = instance.data.get("expectedFiles", [])

# 'expectedFiles' are preferred over 'frames'
if expectedFiles:
# Products with expected files
# This can be Render products or submitted cache to farm.
for expected in expectedFiles:
# expected.values() is a list of lists
expected_filenames.extend(sum(expected.values(), []))
else:
# Products with frames or single file.
frames = instance.data.get("frames", "")
if isinstance(frames, str):
# single file.
expected_filenames.append("{}/{}".format(staging_dir, frames))
else:
# list of frame.
expected_filenames.extend(
["{}/{}".format(staging_dir, f) for f in frames]
)
staging_dir, expected_filenames = self.get_expected_files_and_staging_dir(instance)

os.makedirs(staging_dir, exist_ok=True)

Expand All @@ -87,3 +66,34 @@ def process(self, instance):
if frame and frame not in frames_to_fix:
self.log.debug("Copying '{}' -> '{}'".format(file_path, out_path))
shutil.copy(file_path, out_path)


def get_expected_files_and_staging_dir(self, instance):
""" Get expected file names or frames.
This method includes Houdini specific code.
"""
expected_filenames = []
staging_dir = instance.data.get("stagingDir")
expectedFiles = instance.data.get("expectedFiles", [])

# 'expectedFiles' are preferred over 'frames'
if expectedFiles:
# Products with expected files
# This can be Render products or submitted cache to farm.
for expected in expectedFiles:
# expected.values() is a list of lists
expected_filenames.extend(sum(expected.values(), []))
else:
# Products with frames or single file.
frames = instance.data.get("frames", "")
if isinstance(frames, str):
# single file.
expected_filenames.append("{}/{}".format(staging_dir, frames))
else:
# list of frame.
expected_filenames.extend(
["{}/{}".format(staging_dir, f) for f in frames]
)

return staging_dir, expected_filenames

0 comments on commit 6121964

Please sign in to comment.