Modified publishing plugins to work with general families

This commit is contained in:
Jakub Trllo 2022-04-26 16:15:08 +02:00
parent 1c7c0fef32
commit f1434fa175
6 changed files with 104 additions and 67 deletions

View file

@ -58,6 +58,7 @@ class SettingsCreator(TrayPublishCreator):
def create(self, subset_name, data, pre_create_data):
# Pass precreate data to creator attributes
data["creator_attributes"] = pre_create_data
data["settings_creator"] = True
# Create new instance
new_instance = CreatedInstance(self.family, subset_name, data, self)
# Host implementation of storing metadata about instance

View file

@ -0,0 +1,48 @@
import os
import pyblish.api
class CollectSettingsSimpleInstances(pyblish.api.InstancePlugin):
"""Collect data for instances created by settings creators."""
label = "Collect Settings Simple Instances"
order = pyblish.api.CollectorOrder - 0.49
hosts = ["traypublisher"]
def process(self, instance):
if not instance.data.get("settings_creator"):
return
if "families" not in instance.data:
instance.data["families"] = []
if "representations" not in instance.data:
instance.data["representations"] = []
repres = instance.data["representations"]
creator_attributes = instance.data["creator_attributes"]
if creator_attributes.get("review"):
instance.data["families"].append("review")
filepath_item = creator_attributes["filepath"]
self.log.info(filepath_item)
filepaths = [
os.path.join(filepath_item["directory"], filename)
for filename in filepath_item["filenames"]
]
instance.data["sourceFilepaths"] = filepaths
filenames = filepath_item["filenames"]
ext = os.path.splitext(filenames[0])[-1]
if len(filenames) == 1:
filenames = filenames[0]
repres.append({
"ext": ext,
"name": ext,
"stagingDir": filepath_item["directory"],
"files": filenames
})

View file

@ -1,31 +0,0 @@
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
})

View file

@ -0,0 +1,45 @@
import os
import pyblish.api
from openpype.pipeline import PublishValidationError
class ValidateWorkfilePath(pyblish.api.InstancePlugin):
"""Validate existence of workfile instance existence."""
label = "Validate Workfile"
order = pyblish.api.ValidatorOrder - 0.49
hosts = ["traypublisher"]
def process(self, instance):
if "sourceFilepaths" not in instance.data:
self.log.info((
"Can't validate source filepaths existence."
" Instance does not have collected 'sourceFilepaths'"
))
return
filepaths = instance.data.get("sourceFilepaths")
not_found_files = [
filepath
for filepath in filepaths
if not os.path.exists(filepath)
]
if not_found_files:
joined_paths = "\n".join([
"- {}".format(filepath)
for filepath in not_found_files
])
raise PublishValidationError(
(
"Filepath of '{}' instance \"{}\" does not exist:\n{}"
).format(
instance.data["family"], instance.data["name"], joined_paths
),
"File not found",
(
"## Files were not found\nFiles\n{}"
"\n\nCheck if the path is still available."
).format(joined_paths)
)

View file

@ -1,35 +0,0 @@
import os
import pyblish.api
from openpype.pipeline import PublishValidationError
class ValidateWorkfilePath(pyblish.api.InstancePlugin):
"""Validate existence of workfile instance existence."""
label = "Validate 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"]),
"File not filled",
"## Missing file\nYou are supposed to fill the path."
)
if not os.path.exists(filepath):
raise PublishValidationError(
(
"Filepath of 'workfile' instance \"{}\" does not exist: {}"
).format(instance.data["name"], filepath),
"File not found",
(
"## File was not found\nFile \"{}\" was not found."
" Check if the path is still available."
).format(filepath)
)

View file

@ -405,6 +405,7 @@ class FilesWidget(QtWidgets.QFrame):
files_proxy_model.rowsRemoved.connect(self._on_rows_removed)
files_view.remove_requested.connect(self._on_remove_requested)
self._in_set_value = False
self._single_item = single_item
self._empty_widget = empty_widget
self._files_model = files_model
@ -432,6 +433,9 @@ class FilesWidget(QtWidgets.QFrame):
all_same = False
value = new_value
if not isinstance(value, (list, tuple, set)):
value = [value]
if value:
self._add_filepaths(value)
self._in_set_value = False
@ -448,7 +452,12 @@ class FilesWidget(QtWidgets.QFrame):
file_item = self._files_model.get_file_item_by_id(item_id)
if file_item is not None:
file_items.append(file_item.to_dict())
return file_items
if not self._single_item:
return file_items
if file_items:
return file_items[0]
return FileDefItem.create_empty_item()
def set_filters(self, folders_allowed, exts_filter):
self._files_proxy_model.set_allow_folders(folders_allowed)