Skip to content

Commit

Permalink
refactors mrq job override into own creator and runs only if job is h…
Browse files Browse the repository at this point in the history
…andled automatically
  • Loading branch information
Tony Dorfmeister committed Dec 22, 2024
1 parent c124717 commit 07cb9f0
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 55 deletions.
90 changes: 90 additions & 0 deletions client/ayon_unreal/plugins/publish/collect_render_files_farm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import pyblish.api
from pathlib import Path
from copy import deepcopy

import unreal

from ayon_core.pipeline import Anatomy
from ayon_core.lib import StringTemplate

from ayon_unreal.api.rendering import SUPPORTED_EXTENSION_MAP


class CollectRemoteRenderFiles(pyblish.api.InstancePlugin):
order = pyblish.api.CollectorOrder + 0.497
label = "Collect Remote Render Files"
hosts = ["unreal"]
families = ["render", "render.farm"]

def process(self, instance):
if not instance.context.data.get("auto_handle_mrq"):
self.log.info(
"MRQ isn't automatically built. Skipping render output override."
)
return

self.job = instance.data["mrq_job"]
self.mrq = instance.context.data["mrq"]
self.anatomy_data = deepcopy(instance.data["anatomyData"])
self.project_data = deepcopy(instance.data["projectEntity"])

self.job_config = self.job.get_configuration()
(work_dir, work_file) = self.get_path_overrides()

# overrides jobs output directory and file name
ue_dir_override = unreal.DirectoryPath()
ue_dir_override.path = Path(work_dir).as_posix()
ue_file_override = work_file + ".{frame_number}"
job_output_settings = self.job_config.find_setting_by_class(
unreal.MoviePipelineOutputSetting
)
job_output_settings.set_editor_property("output_directory", ue_dir_override)
job_output_settings.set_editor_property("file_name_format", ue_file_override)

# override expected files
exp_files_override = []
for exp_file in instance.data["expectedFiles"]:
splits = exp_file.split(".")
exp_file_override = work_dir / f"{work_file}.{splits[1]}.{splits[2]}"
exp_files_override.append(exp_file_override.as_posix())
instance.data["expectedFiles"] = exp_files_override

def get_path_overrides(self):
self._get_work_file_template()

# build output directory
exr_settings = self.job_config.find_setting_by_class(
unreal.MoviePipelineImageSequenceOutput_EXR
)
if not exr_settings:
raise Exception("No EXR settings found in the job configuration.")

# initialize template data
anatomy = Anatomy(self.project_data["name"])
template_data = self.anatomy_data
template_data["root"] = anatomy.roots
template_data["ext"] = "exr"

# format the publish path
project_templates = self.project_data["config"]["templates"]
template_data["version"] = (
f"v{template_data['version']:0{project_templates['common']['version_padding']}d}"
)
work_dir = self.dir_template.format_strict(template_data)
work_file = self.file_template.format_strict(template_data)

return (Path(work_dir), Path(work_file).stem)

def _get_work_file_template(self):
# get work file template
# how can i build a @token?
project_templates = self.project_data["config"]["templates"]
_dir_template = project_templates["work"]["default"][
"directory"
].replace("@version", "version")
_file_template = project_templates["work"]["default"]["file"].replace(
"@version", "version"
)

self.dir_template = StringTemplate(_dir_template)
self.file_template = StringTemplate(_file_template)
55 changes: 0 additions & 55 deletions client/ayon_unreal/plugins/publish/validate_mrq.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@ def process(self, instance):
- checks if user has latest p4 changes synced
"""
self.curr_mrq = instance.context.data["mrq"]
self.anatomy_data = deepcopy(instance.data["anatomyData"])
self.project_data = deepcopy(instance.data["projectEntity"])

self.validate_no_dirty_packages()
self.validate_map()
self.validate_instance_in_mrq(instance)
self.set_output_path(instance.data["mrq_job"])

# TODO: implement p4 checks

Expand Down Expand Up @@ -85,55 +82,3 @@ def validate_instance_in_mrq(self, instance):
"Instance not found in Media Render Queue. Try to clear your current MRQ and try again."
)

def set_output_path(self, job):
self._get_work_file_template()

# build output directory
job_config = job.get_configuration()
exr_settings = job_config.find_setting_by_class(
unreal.MoviePipelineImageSequenceOutput_EXR
)
if not exr_settings:
raise Exception("No EXR settings found in the job configuration.")

# initialize template data
anatomy = Anatomy(self.project_data["name"])
template_data = self.anatomy_data
template_data["root"] = anatomy.roots
template_data["ext"] = "exr"

# format the publish path
project_templates = self.project_data["config"]["templates"]
template_data["version"] = (
f"v{template_data['version']:0{project_templates['common']['version_padding']}d}"
)
work_dir = Path(self.dir_template.format_strict(template_data))
work_file = Path(self.file_template.format_strict(template_data))
output_settings = job_config.find_setting_by_class(
unreal.MoviePipelineOutputSetting
)

output_dir_override = unreal.DirectoryPath()
output_dir_override.path = work_dir.as_posix()
output_file_override = work_file.stem + ".{frame_number}"

output_settings.set_editor_property(
"output_directory", output_dir_override
)
output_settings.set_editor_property(
"file_name_format", output_file_override
)

def _get_work_file_template(self):
# get work file template
# how can i build a @token?
project_templates = self.project_data["config"]["templates"]
_dir_template = project_templates["work"]["default"][
"directory"
].replace("@version", "version")
_file_template = project_templates["work"]["default"]["file"].replace(
"@version", "version"
)

self.dir_template = StringTemplate(_dir_template)
self.file_template = StringTemplate(_file_template)

0 comments on commit 07cb9f0

Please sign in to comment.