From a8c219211d5f2dddaf6b4dd31fd59d1137bbd0c1 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Fri, 15 Jul 2022 13:25:42 +0200 Subject: [PATCH 1/6] OP-3589 - copied ValidateFrameRange from SP SP will be removed in the future, copied this to TrayPublisher to keep functionality. --- .../publish/help/validate_frame_ranges.xml | 15 ++++ .../plugins/publish/validate_frame_ranges.py | 72 +++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 openpype/hosts/traypublisher/plugins/publish/help/validate_frame_ranges.xml create mode 100644 openpype/hosts/traypublisher/plugins/publish/validate_frame_ranges.py diff --git a/openpype/hosts/traypublisher/plugins/publish/help/validate_frame_ranges.xml b/openpype/hosts/traypublisher/plugins/publish/help/validate_frame_ranges.xml new file mode 100644 index 0000000000..933df1c7c5 --- /dev/null +++ b/openpype/hosts/traypublisher/plugins/publish/help/validate_frame_ranges.xml @@ -0,0 +1,15 @@ + + + +Invalid frame range + +## Invalid frame range + +Expected duration or '{duration}' frames set in database, workfile contains only '{found}' frames. + +### How to repair? + +Modify configuration in the database or tweak frame range in the workfile. + + + \ No newline at end of file diff --git a/openpype/hosts/traypublisher/plugins/publish/validate_frame_ranges.py b/openpype/hosts/traypublisher/plugins/publish/validate_frame_ranges.py new file mode 100644 index 0000000000..89289fc6d4 --- /dev/null +++ b/openpype/hosts/traypublisher/plugins/publish/validate_frame_ranges.py @@ -0,0 +1,72 @@ +import re + +import pyblish.api + +import openpype.api +from openpype import lib +from openpype.pipeline import ( + PublishXmlValidationError, + OptionalPyblishPluginMixin +) + + +class ValidateFrameRange(OptionalPyblishPluginMixin, + pyblish.api.InstancePlugin): + """Validating frame range of rendered files against state in DB.""" + + label = "Validate Frame Range" + hosts = ["traypublisher"] + families = ["render"] + order = openpype.api.ValidateContentsOrder + + optional = True + # published data might be sequence (.mov, .mp4) in that counting files + # doesnt make sense + check_extensions = ["exr", "dpx", "jpg", "jpeg", "png", "tiff", "tga", + "gif", "svg"] + skip_timelines_check = [] # skip for specific task names (regex) + + def process(self, instance): + # Skip the instance if is not active by data on the instance + if not self.is_active(instance.data): + return + + if any(re.search(pattern, instance.data["task"]) + for pattern in self.skip_timelines_check): + self.log.info("Skipping for {} task".format(instance.data["task"])) + + asset_data = lib.get_asset(instance.data["asset"])["data"] + frame_start = asset_data["frameStart"] + frame_end = asset_data["frameEnd"] + handle_start = asset_data["handleStart"] + handle_end = asset_data["handleEnd"] + duration = (frame_end - frame_start + 1) + handle_start + handle_end + + repre = instance.data.get("representations", [None]) + if not repre: + self.log.info("No representations, skipping.") + return + + ext = repre[0]['ext'].replace(".", '') + + if not ext or ext.lower() not in self.check_extensions: + self.log.warning("Cannot check for extension {}".format(ext)) + return + + files = instance.data.get("representations", [None])[0]["files"] + if isinstance(files, str): + files = [files] + frames = len(files) + + msg = "Frame duration from DB:'{}' ". format(int(duration)) +\ + " doesn't match number of files:'{}'".format(frames) +\ + " Please change frame range for Asset or limit no. of files" + + formatting_data = {"duration": duration, + "found": frames} + if frames != duration: + raise PublishXmlValidationError(self, msg, + formatting_data=formatting_data) + + self.log.debug("Valid ranges expected '{}' - found '{}'". + format(int(duration), frames)) From 247db779fe416c663d0b8e4ae100284fe9977476 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Mon, 18 Jul 2022 10:56:08 +0200 Subject: [PATCH 2/6] Update openpype/hosts/traypublisher/plugins/publish/validate_frame_ranges.py Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> --- .../traypublisher/plugins/publish/validate_frame_ranges.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/openpype/hosts/traypublisher/plugins/publish/validate_frame_ranges.py b/openpype/hosts/traypublisher/plugins/publish/validate_frame_ranges.py index 89289fc6d4..bb6b906e8d 100644 --- a/openpype/hosts/traypublisher/plugins/publish/validate_frame_ranges.py +++ b/openpype/hosts/traypublisher/plugins/publish/validate_frame_ranges.py @@ -58,9 +58,10 @@ class ValidateFrameRange(OptionalPyblishPluginMixin, files = [files] frames = len(files) - msg = "Frame duration from DB:'{}' ". format(int(duration)) +\ - " doesn't match number of files:'{}'".format(frames) +\ - " Please change frame range for Asset or limit no. of files" + msg = ( + "Frame duration from DB:'{}' doesn't match number of files:'{}'" + " Please change frame range for Asset or limit no. of files" + ). format(int(duration), frames) formatting_data = {"duration": duration, "found": frames} From cdabfbe6f9d0ea90df1a44525bf0ae88a45c825d Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Mon, 18 Jul 2022 10:56:25 +0200 Subject: [PATCH 3/6] Update openpype/hosts/traypublisher/plugins/publish/validate_frame_ranges.py Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> --- .../traypublisher/plugins/publish/validate_frame_ranges.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openpype/hosts/traypublisher/plugins/publish/validate_frame_ranges.py b/openpype/hosts/traypublisher/plugins/publish/validate_frame_ranges.py index bb6b906e8d..0d7081139d 100644 --- a/openpype/hosts/traypublisher/plugins/publish/validate_frame_ranges.py +++ b/openpype/hosts/traypublisher/plugins/publish/validate_frame_ranges.py @@ -35,7 +35,8 @@ class ValidateFrameRange(OptionalPyblishPluginMixin, for pattern in self.skip_timelines_check): self.log.info("Skipping for {} task".format(instance.data["task"])) - asset_data = lib.get_asset(instance.data["asset"])["data"] + asset_doc = instance.data["assetEntity"] + asset_data = asset_doc["data"] frame_start = asset_data["frameStart"] frame_end = asset_data["frameEnd"] handle_start = asset_data["handleStart"] From ef2284e507cd43db6b14518244333d10db1091b6 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Mon, 18 Jul 2022 10:57:01 +0200 Subject: [PATCH 4/6] Update openpype/hosts/traypublisher/plugins/publish/validate_frame_ranges.py Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> --- .../plugins/publish/validate_frame_ranges.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/openpype/hosts/traypublisher/plugins/publish/validate_frame_ranges.py b/openpype/hosts/traypublisher/plugins/publish/validate_frame_ranges.py index 0d7081139d..6d48e8352c 100644 --- a/openpype/hosts/traypublisher/plugins/publish/validate_frame_ranges.py +++ b/openpype/hosts/traypublisher/plugins/publish/validate_frame_ranges.py @@ -43,18 +43,19 @@ class ValidateFrameRange(OptionalPyblishPluginMixin, handle_end = asset_data["handleEnd"] duration = (frame_end - frame_start + 1) + handle_start + handle_end - repre = instance.data.get("representations", [None]) - if not repre: + repres = instance.data.get("representations") + if not repres: self.log.info("No representations, skipping.") return - - ext = repre[0]['ext'].replace(".", '') + + first_repre = repres[0] + ext = first_repre['ext'].replace(".", '') if not ext or ext.lower() not in self.check_extensions: self.log.warning("Cannot check for extension {}".format(ext)) return - files = instance.data.get("representations", [None])[0]["files"] + files = first_repre["files"] if isinstance(files, str): files = [files] frames = len(files) From 247eaf792bb21fd294bf95bb64423965834a4b00 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Mon, 18 Jul 2022 11:01:30 +0200 Subject: [PATCH 5/6] Check only if skip_timelines_check is filled --- .../traypublisher/plugins/publish/validate_frame_ranges.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/openpype/hosts/traypublisher/plugins/publish/validate_frame_ranges.py b/openpype/hosts/traypublisher/plugins/publish/validate_frame_ranges.py index 6d48e8352c..65b6128cbe 100644 --- a/openpype/hosts/traypublisher/plugins/publish/validate_frame_ranges.py +++ b/openpype/hosts/traypublisher/plugins/publish/validate_frame_ranges.py @@ -31,8 +31,9 @@ class ValidateFrameRange(OptionalPyblishPluginMixin, if not self.is_active(instance.data): return - if any(re.search(pattern, instance.data["task"]) - for pattern in self.skip_timelines_check): + if (self.skip_timelines_check and + any(re.search(pattern, instance.data["task"]) + for pattern in self.skip_timelines_check)): self.log.info("Skipping for {} task".format(instance.data["task"])) asset_doc = instance.data["assetEntity"] From e21338424ed92c4b59422f487de6de501d756c3c Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Mon, 18 Jul 2022 11:02:50 +0200 Subject: [PATCH 6/6] Hound --- .../traypublisher/plugins/publish/validate_frame_ranges.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/openpype/hosts/traypublisher/plugins/publish/validate_frame_ranges.py b/openpype/hosts/traypublisher/plugins/publish/validate_frame_ranges.py index 65b6128cbe..947624100a 100644 --- a/openpype/hosts/traypublisher/plugins/publish/validate_frame_ranges.py +++ b/openpype/hosts/traypublisher/plugins/publish/validate_frame_ranges.py @@ -3,7 +3,6 @@ import re import pyblish.api import openpype.api -from openpype import lib from openpype.pipeline import ( PublishXmlValidationError, OptionalPyblishPluginMixin @@ -48,7 +47,7 @@ class ValidateFrameRange(OptionalPyblishPluginMixin, if not repres: self.log.info("No representations, skipping.") return - + first_repre = repres[0] ext = first_repre['ext'].replace(".", '')