Validate workfile saved once; not per instance - refactored to ContextPlugin

This commit is contained in:
Roy Nieterau 2023-11-13 23:53:17 +01:00
parent ae6c810ba5
commit 1e7ef83b18

View file

@ -18,7 +18,7 @@ class SaveWorkfileAction(pyblish.api.Action):
bpy.ops.wm.avalon_workfiles()
class ValidateFileSaved(pyblish.api.InstancePlugin,
class ValidateFileSaved(pyblish.api.ContextPlugin,
OptionalPyblishPluginMixin):
"""Validate that the workfile has been saved."""
@ -29,18 +29,33 @@ class ValidateFileSaved(pyblish.api.InstancePlugin,
exclude_families = []
actions = [SaveWorkfileAction]
def process(self, instance):
if not self.is_active(instance.data):
def process(self, context):
if not self.is_active(context.data):
return
if not instance.context.data["currentFile"]:
if not context.data["currentFile"]:
# File has not been saved at all and has no filename
raise PublishValidationError(
"Current file is empty. Save the file before continuing."
)
if [ef for ef in self.exclude_families
if instance.data["family"] in ef]:
# Do not validate workfile has unsaved changes if only instances
# present of families that should be excluded
families = {
instance.data["family"] for instance in context
# Consider only enabled instances
if instance.data.get("publish", True)
and instance.data.get("active", True)
}
def is_excluded(family):
return any(family in exclude_family
for exclude_family in self.exclude_families)
if all(is_excluded(family) for family in families):
self.log.debug("Only excluded families found, skipping workfile "
"unsaved changes validation..")
return
if bpy.data.is_dirty:
raise PublishValidationError("Workfile has unsaved changes.")