mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-02 08:54:53 +01:00
Collect subset group in a Collector instead of during Integrator
This commit is contained in:
parent
e0aaa5f6cc
commit
d3cb32ebe1
2 changed files with 100 additions and 50 deletions
100
openpype/plugins/publish/collect_subset_group.py
Normal file
100
openpype/plugins/publish/collect_subset_group.py
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
"""Produces instance.data["subsetGroup"] data used during integration.
|
||||
|
||||
Requires:
|
||||
dict -> context["anatomyData"] *(pyblish.api.CollectorOrder + 0.49)
|
||||
|
||||
Provides:
|
||||
instance -> subsetGroup (str)
|
||||
|
||||
"""
|
||||
import pyblish.api
|
||||
|
||||
from openpype.lib.profiles_filtering import filter_profiles
|
||||
from openpype.lib import (
|
||||
prepare_template_data,
|
||||
StringTemplate,
|
||||
TemplateUnsolved
|
||||
)
|
||||
|
||||
|
||||
class CollectSubsetGroup(pyblish.api.ContextPlugin):
|
||||
"""Collect Subset Group for publish."""
|
||||
|
||||
# Run after CollectAnatomyInstanceData
|
||||
order = pyblish.api.CollectorOrder + 0.495
|
||||
label = "Collect Subset Group"
|
||||
|
||||
def process(self, instance):
|
||||
"""Look into subset group profiles set by settings.
|
||||
|
||||
Attribute 'subset_grouping_profiles' is defined by OpenPype settings.
|
||||
"""
|
||||
|
||||
# TODO: Move this setting to this Collector instead of Integrator
|
||||
project_settings = instance.context.data["project_settings"]
|
||||
subset_grouping_profiles = (
|
||||
project_settings["global"]
|
||||
["publish"]
|
||||
["IntegrateAssetNew"]
|
||||
["subset_grouping_profiles"]
|
||||
)
|
||||
|
||||
# Skip if 'subset_grouping_profiles' is empty
|
||||
if not subset_grouping_profiles:
|
||||
return
|
||||
|
||||
# Skip if there is no matching profile
|
||||
filter_criteria = self.get_profile_filter_criteria(instance)
|
||||
profile = filter_profiles(subset_grouping_profiles,
|
||||
filter_criteria,
|
||||
logger=self.log)
|
||||
if not profile:
|
||||
return
|
||||
|
||||
if instance.data.get("subsetGroup"):
|
||||
# If subsetGroup is already set then allow that value to remain
|
||||
self.log.debug("Skipping collect subset group due to existing "
|
||||
"value: {}".format(instance.data["subsetGroup"]))
|
||||
return
|
||||
|
||||
template = profile["template"]
|
||||
|
||||
fill_pairs = prepare_template_data({
|
||||
"family": filter_criteria["families"],
|
||||
"task": filter_criteria["tasks"],
|
||||
"host": filter_criteria["hosts"],
|
||||
"subset": instance.data["subset"],
|
||||
"renderlayer": instance.data.get("renderlayer")
|
||||
})
|
||||
|
||||
filled_template = None
|
||||
try:
|
||||
filled_template = StringTemplate.format_strict_template(
|
||||
template, fill_pairs
|
||||
)
|
||||
except (KeyError, TemplateUnsolved):
|
||||
keys = fill_pairs.keys()
|
||||
msg = "Subset grouping failed. " \
|
||||
"Only {} are expected in Settings".format(','.join(keys))
|
||||
self.log.warning(msg)
|
||||
|
||||
if filled_template:
|
||||
instance.data["subsetGroup"] = filled_template
|
||||
|
||||
def get_profile_filter_criteria(self, instance):
|
||||
"""Return filter criteria for `filter_profiles`"""
|
||||
# TODO: This logic is used in much more plug-ins in one way or another
|
||||
# Maybe better suited for lib?
|
||||
# Anatomy data is pre-filled by Collectors
|
||||
anatomy_data = instance.data["anatomyData"]
|
||||
|
||||
# Task can be optional in anatomy data
|
||||
task = anatomy_data.get("task", {})
|
||||
|
||||
# Return filter criteria
|
||||
return {
|
||||
"families": anatomy_data["family"],
|
||||
"tasks": task.get("name"),
|
||||
"hosts": anatomy_data["app"],
|
||||
"task_types": task.get("type")
|
||||
}
|
||||
|
|
@ -13,11 +13,6 @@ import openpype.api
|
|||
from datetime import datetime
|
||||
from openpype.lib.profiles_filtering import filter_profiles
|
||||
from openpype.lib.file_transaction import FileTransaction
|
||||
from openpype.lib import (
|
||||
prepare_template_data,
|
||||
StringTemplate,
|
||||
TemplateUnsolved
|
||||
)
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
|
@ -619,9 +614,6 @@ class IntegrateAssetNew(pyblish.api.InstancePlugin):
|
|||
}
|
||||
|
||||
subset_group = instance.data.get("subsetGroup")
|
||||
if not subset_group:
|
||||
# todo: move _get_subset_group fallback to its own collector
|
||||
subset_group = self._get_subset_group(instance)
|
||||
if subset_group:
|
||||
data["subsetGroup"] = subset_group
|
||||
|
||||
|
|
@ -653,48 +645,6 @@ class IntegrateAssetNew(pyblish.api.InstancePlugin):
|
|||
self.log.info("Registered subset: {}".format(subset_name))
|
||||
return subset
|
||||
|
||||
def _get_subset_group(self, instance):
|
||||
"""Look into subset group profiles set by settings.
|
||||
|
||||
Attribute 'subset_grouping_profiles' is defined by OpenPype settings.
|
||||
"""
|
||||
# TODO: This logic is better suited for a Collector to just store
|
||||
# instance.data["subsetGroup"]
|
||||
# Skip if 'subset_grouping_profiles' is empty
|
||||
if not self.subset_grouping_profiles:
|
||||
return None
|
||||
|
||||
# Skip if there is no matching profile
|
||||
filter_criteria = self.get_profile_filter_criteria(instance)
|
||||
profile = filter_profiles(self.subset_grouping_profiles,
|
||||
filter_criteria,
|
||||
logger=self.log)
|
||||
if not profile:
|
||||
return None
|
||||
|
||||
template = profile["template"]
|
||||
|
||||
fill_pairs = prepare_template_data({
|
||||
"family": filter_criteria["families"],
|
||||
"task": filter_criteria["tasks"],
|
||||
"host": filter_criteria["hosts"],
|
||||
"subset": instance.data["subset"],
|
||||
"renderlayer": instance.data.get("renderlayer")
|
||||
})
|
||||
|
||||
filled_template = None
|
||||
try:
|
||||
filled_template = StringTemplate.format_strict_template(
|
||||
template, fill_pairs
|
||||
)
|
||||
except (KeyError, TemplateUnsolved):
|
||||
keys = fill_pairs.keys()
|
||||
msg = "Subset grouping failed. " \
|
||||
"Only {} are expected in Settings".format(','.join(keys))
|
||||
self.log.warning(msg)
|
||||
|
||||
return filled_template
|
||||
|
||||
def create_version_data(self, instance):
|
||||
"""Create the data collection for the version
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue