From 026d9688fec9b4f8c259e891760964a75fe26d57 Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Mon, 21 Feb 2022 17:23:35 +0100 Subject: [PATCH] added collector and validator for workfile family --- .../plugins/publish/collect_workfile.py | 31 +++++++++++++++++++ .../plugins/publish/validate_workfile.py | 24 ++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 openpype/hosts/traypublisher/plugins/publish/collect_workfile.py create mode 100644 openpype/hosts/traypublisher/plugins/publish/validate_workfile.py diff --git a/openpype/hosts/traypublisher/plugins/publish/collect_workfile.py b/openpype/hosts/traypublisher/plugins/publish/collect_workfile.py new file mode 100644 index 0000000000..d48bace047 --- /dev/null +++ b/openpype/hosts/traypublisher/plugins/publish/collect_workfile.py @@ -0,0 +1,31 @@ +import os +import pyblish.api + + +class CollectWorkfile(pyblish.api.InstancePlugin): + """Collect representation of workfile instances.""" + + label = "Collect Workfile" + order = pyblish.api.CollectorOrder - 0.49 + families = ["workfile"] + hosts = ["traypublisher"] + + def process(self, instance): + if "representations" not in instance.data: + instance.data["representations"] = [] + repres = instance.data["representations"] + + creator_attributes = instance.data["creator_attributes"] + filepath = creator_attributes["filepath"] + instance.data["sourceFilepath"] = filepath + + staging_dir = os.path.dirname(filepath) + filename = os.path.basename(filepath) + ext = os.path.splitext(filename)[-1] + + repres.append({ + "ext": ext, + "name": ext, + "stagingDir": staging_dir, + "files": filename + }) diff --git a/openpype/hosts/traypublisher/plugins/publish/validate_workfile.py b/openpype/hosts/traypublisher/plugins/publish/validate_workfile.py new file mode 100644 index 0000000000..88339d2aac --- /dev/null +++ b/openpype/hosts/traypublisher/plugins/publish/validate_workfile.py @@ -0,0 +1,24 @@ +import os +import pyblish.api +from openpype.pipeline import PublishValidationError + + +class ValidateWorkfilePath(pyblish.api.InstancePlugin): + """Validate existence of workfile instance existence.""" + + label = "Collect Workfile" + order = pyblish.api.ValidatorOrder - 0.49 + families = ["workfile"] + hosts = ["traypublisher"] + + def process(self, instance): + filepath = instance.data["sourceFilepath"] + if not filepath: + raise PublishValidationError(( + "Filepath of 'workfile' instance \"{}\" is not set" + ).format(instance.data["name"])) + + if not os.path.exists(filepath): + raise PublishValidationError(( + "Filepath of 'workfile' instance \"{}\" does not exist: {}" + ).format(instance.data["name"], filepath))