diff --git a/openpype/hosts/tvpaint/plugins/publish/validate_workfile_data.py b/openpype/hosts/tvpaint/plugins/publish/validate_workfile_data.py new file mode 100644 index 0000000000..3a89557c3e --- /dev/null +++ b/openpype/hosts/tvpaint/plugins/publish/validate_workfile_data.py @@ -0,0 +1,49 @@ +import json + +import pyblish.api +from avalon.tvpaint import save_file + + +class ValidateWorkfileMetadataRepair(pyblish.api.Action): + """Store current context into workfile metadata.""" + + label = "Use current context" + icon = "wrench" + on = "failed" + + def process(self, context, plugin): + """Save current workfile which should trigger storing of metadata.""" + current_file = context.data["currentFile"] + # Save file should trigger + save_file(current_file) + + +class ValidateWorkfileMetadata(pyblish.api.ContextPlugin): + """Validate if wokrfile contain required metadata for publising.""" + + label = "Validate Workfile Metadata" + order = pyblish.api.ValidatorOrder + + families = ["workfile"] + + required_keys = {"project", "asset", "task"} + + def process(self, context): + workfile_context = context.data["workfile_context"] + if not workfile_context: + raise AssertionError( + "Current workfile is missing whole metadata about context." + ) + + missing_keys = [] + for key in self.required_keys: + value = workfile_context.get(key) + if not value: + missing_keys.append(key) + + if missing_keys: + raise AssertionError( + "Current workfile is missing metadata about {}.".format( + ", ".join(missing_keys) + ) + )