PS subset group - added new standard function

Implementation should follow Create subset name approach
This commit is contained in:
Petr Kalis 2021-05-04 16:03:23 +02:00
parent d92d70a4df
commit 623f19c5fa
4 changed files with 34 additions and 11 deletions

View file

@ -112,6 +112,7 @@ from .profiles_filtering import filter_profiles
from .plugin_tools import (
TaskNotSetError,
get_subset_name,
prepare_template_data,
filter_pyblish_plugins,
source_hash,
get_unique_layer_name,

View file

@ -73,6 +73,23 @@ def get_subset_name(
("family", family),
("task", task_name)
)
return template.format(**prepare_template_data(fill_pairs))
def prepare_template_data(fill_pairs):
"""
Prepares formatted data for filling template.
It produces mutliple variants of keys (key, Key, KEY) to control
format of filled template.
Args:
fill_pairs (iterable) of tuples (key, value)
Returns:
(dict)
('host', 'maya') > {'host':'maya', 'Host': 'Maya', 'HOST': 'MAYA'}
"""
fill_data = {}
for key, value in fill_pairs:
# Handle cases when value is `None` (standalone publisher)
@ -94,7 +111,7 @@ def get_subset_name(
capitalized += value[1:]
fill_data[key.capitalize()] = capitalized
return template.format(**fill_data)
return fill_data
def filter_pyblish_plugins(plugins):

View file

@ -12,11 +12,13 @@ import shutil
from pymongo import DeleteOne, InsertOne
import pyblish.api
from avalon import io
from avalon.api import format_template_with_optional_keys
from avalon.vendor import filelink
import openpype.api
from datetime import datetime
# from pype.modules import ModulesManager
from openpype.lib.profiles_filtering import filter_profiles
from openpype.lib import prepare_template_data
# this is needed until speedcopy for linux is fixed
if sys.platform == "win32":
@ -730,7 +732,7 @@ class IntegrateAssetNew(pyblish.api.InstancePlugin):
profiles = integrate_new_sett["subset_grouping_profiles"]
filtering_criteria = {
"families": instance.data["anatomyData"]["family"],
"families": instance.data["family"],
"hosts": instance.data["anatomyData"]["app"],
"tasks": instance.data["anatomyData"]["task"] or
io.Session["AVALON_TASK"]
@ -738,17 +740,20 @@ class IntegrateAssetNew(pyblish.api.InstancePlugin):
matching_profile = filter_profiles(profiles, filtering_criteria)
filled_template = None
fill_pairs = None
if matching_profile:
template = matching_profile["template"]
fill_pairs = {
"family": filtering_criteria["families"],
"task": filtering_criteria["tasks"],
"Family": filtering_criteria["families"].capitalize(),
"Task": filtering_criteria["tasks"].capitalize()
}
fill_pairs = (
("family", filtering_criteria["families"]),
("task", filtering_criteria["tasks"]),
("host", filtering_criteria["hosts"]),
("subset", instance.data["subset"]),
("renderlayer", instance.data.get("renderlayer"))
)
fill_pairs = prepare_template_data(fill_pairs)
try:
filled_template = template.format(**fill_pairs)
filled_template = \
format_template_with_optional_keys(fill_pairs, template)
except KeyError:
keys = []
if fill_pairs:

View file

@ -427,7 +427,7 @@
"children": [
{
"type": "label",
"label": "Set all published instances as a part of specific group named according to 'Template'. <br>Implemented placeholders [{task},{Task},{family},{Family}]"
"label": "Set all published instances as a part of specific group named according to 'Template'. <br>Implemented all variants of placeholders [{task},{family},{host},{subset},{renderlayer}]"
},
{
"key": "families",