mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-26 22:02:15 +01:00
Validate workfile saved once; not per instance - refactored to ContextPlugin
This commit is contained in:
parent
ae6c810ba5
commit
1e7ef83b18
1 changed files with 21 additions and 6 deletions
|
|
@ -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.")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue