From 07cb9f09d9c110790db81b21283c6a720620b25b Mon Sep 17 00:00:00 2001 From: Tony Dorfmeister Date: Sun, 22 Dec 2024 21:30:56 +0100 Subject: [PATCH] refactors mrq job override into own creator and runs only if job is handled automatically --- .../publish/collect_render_files_farm.py | 90 +++++++++++++++++++ .../plugins/publish/validate_mrq.py | 55 ------------ 2 files changed, 90 insertions(+), 55 deletions(-) create mode 100644 client/ayon_unreal/plugins/publish/collect_render_files_farm.py diff --git a/client/ayon_unreal/plugins/publish/collect_render_files_farm.py b/client/ayon_unreal/plugins/publish/collect_render_files_farm.py new file mode 100644 index 00000000..c1814f6b --- /dev/null +++ b/client/ayon_unreal/plugins/publish/collect_render_files_farm.py @@ -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) diff --git a/client/ayon_unreal/plugins/publish/validate_mrq.py b/client/ayon_unreal/plugins/publish/validate_mrq.py index 7817fd05..fcfd3c44 100644 --- a/client/ayon_unreal/plugins/publish/validate_mrq.py +++ b/client/ayon_unreal/plugins/publish/validate_mrq.py @@ -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 @@ -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)