Merge pull request #1416 from pypeclub/3.0/feature/PS_group_subset_by_task_name

This commit is contained in:
Milan Kolar 2021-05-06 20:29:26 +02:00 committed by GitHub
commit b59da71aa9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 132 additions and 10 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,
set_plugin_attributes_from_settings,
source_hash,

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,10 +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":
@ -697,14 +700,7 @@ class IntegrateAssetNew(pyblish.api.InstancePlugin):
subset = io.find_one({"_id": _id})
# add group if available
if instance.data.get("subsetGroup"):
io.update_many({
'type': 'subset',
'_id': io.ObjectId(subset["_id"])
}, {'$set': {'data.subsetGroup':
instance.data.get('subsetGroup')}}
)
self._set_subset_group(instance, subset["_id"])
# Update families on subset.
families = [instance.data["family"]]
@ -716,6 +712,65 @@ class IntegrateAssetNew(pyblish.api.InstancePlugin):
return subset
def _set_subset_group(self, instance, subset_id):
"""
Mark subset as belonging to group in DB.
Uses Settings > Global > Publish plugins > IntegrateAssetNew
Args:
instance (dict): processed instance
subset_id (str): DB's subset _id
"""
# add group if available
integrate_new_sett = (instance.context.data["project_settings"]
["global"]
["publish"]
["IntegrateAssetNew"])
profiles = integrate_new_sett["subset_grouping_profiles"]
filtering_criteria = {
"families": instance.data["family"],
"hosts": instance.data["anatomyData"]["app"],
"tasks": instance.data["anatomyData"]["task"] or
io.Session["AVALON_TASK"]
}
matching_profile = filter_profiles(profiles, filtering_criteria)
filled_template = None
if matching_profile:
template = matching_profile["template"]
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 = \
format_template_with_optional_keys(fill_pairs, template)
except KeyError:
keys = []
if fill_pairs:
keys = fill_pairs.keys()
msg = "Subset grouping failed. " \
"Only {} are expected in Settings".format(','.join(keys))
self.log.warning(msg)
if instance.data.get("subsetGroup") or filled_template:
subset_group = instance.data.get('subsetGroup') or filled_template
io.update_many({
'type': 'subset',
'_id': io.ObjectId(subset_id)
}, {'$set': {'data.subsetGroup': subset_group}})
def create_version(self, subset, version_number, data=None):
""" Copy given source to destination

View file

@ -128,7 +128,15 @@
"prerender"
]
}
}
},
"subset_grouping_profiles": [
{
"families": [],
"hosts": [],
"tasks": [],
"template": ""
}
]
},
"ProcessSubmittedJobOnFarm": {
"enabled": true,

View file

@ -423,6 +423,47 @@
"type": "raw-json",
"key": "template_name_profiles",
"label": "template_name_profiles"
},
{
"type": "list",
"key": "subset_grouping_profiles",
"label": "Subset grouping profiles",
"use_label_wrap": true,
"object_type": {
"type": "dict",
"children": [
{
"type": "label",
"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",
"label": "Families",
"type": "list",
"object_type": "text"
},
{
"key": "hosts",
"label": "Hosts",
"type": "list",
"object_type": "text"
},
{
"key": "tasks",
"label": "Task names",
"type": "list",
"object_type": "text"
},
{
"type": "separator"
},
{
"type": "text",
"key": "template",
"label": "Template"
}
]
}
}
]
},