Merge pull request #2417 from pypeclub/bugfix/OP-2038_Photoshop-Layer-naming-inconsistency

PS: Introduced settings for invalid characters to use in ValidateNaming plugin
This commit is contained in:
Petr Kalis 2021-12-16 18:18:25 +01:00 committed by GitHub
commit 249171bd65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 75 additions and 25 deletions

View file

@ -1,3 +1,5 @@
import re
import pyblish.api
import openpype.api
from avalon import photoshop
@ -19,20 +21,33 @@ class ValidateNamingRepair(pyblish.api.Action):
and result["instance"] not in failed):
failed.append(result["instance"])
invalid_chars, replace_char = plugin.get_replace_chars()
self.log.info("{} --- {}".format(invalid_chars, replace_char))
# Apply pyblish.logic to get the instances for the plug-in
instances = pyblish.api.instances_by_plugin(failed, plugin)
stub = photoshop.stub()
for instance in instances:
self.log.info("validate_naming instance {}".format(instance))
name = instance.data["name"].replace(" ", "_")
name = name.replace(instance.data["family"], '')
instance[0].Name = name
data = stub.read(instance[0])
data["subset"] = "image" + name
stub.imprint(instance[0], data)
metadata = stub.read(instance[0])
self.log.info("metadata instance {}".format(metadata))
layer_name = None
if metadata.get("uuid"):
layer_data = stub.get_layer(metadata["uuid"])
self.log.info("layer_data {}".format(layer_data))
if layer_data:
layer_name = re.sub(invalid_chars,
replace_char,
layer_data.name)
name = stub.PUBLISH_ICON + name
stub.rename_layer(instance.data["uuid"], name)
stub.rename_layer(instance.data["uuid"], layer_name)
subset_name = re.sub(invalid_chars, replace_char,
instance.data["name"])
instance[0].Name = layer_name or subset_name
metadata["subset"] = subset_name
stub.imprint(instance[0], metadata)
return True
@ -49,12 +64,21 @@ class ValidateNaming(pyblish.api.InstancePlugin):
families = ["image"]
actions = [ValidateNamingRepair]
# configured by Settings
invalid_chars = ''
replace_char = ''
def process(self, instance):
help_msg = ' Use Repair action (A) in Pyblish to fix it.'
msg = "Name \"{}\" is not allowed.{}".format(instance.data["name"],
help_msg)
assert " " not in instance.data["name"], msg
assert not re.search(self.invalid_chars, instance.data["name"]), msg
msg = "Subset \"{}\" is not allowed.{}".format(instance.data["subset"],
help_msg)
assert " " not in instance.data["subset"], msg
assert not re.search(self.invalid_chars, instance.data["subset"]), msg
@classmethod
def get_replace_chars(cls):
"""Pass values configured in Settings for Repair."""
return cls.invalid_chars, cls.replace_char

View file

@ -7,11 +7,6 @@
}
},
"publish": {
"ValidateContainers": {
"enabled": true,
"optional": true,
"active": true
},
"CollectRemoteInstances": {
"color_code_mapping": [
{
@ -22,6 +17,15 @@
}
]
},
"ValidateContainers": {
"enabled": true,
"optional": true,
"active": true
},
"ValidateNaming": {
"invalid_chars": "[ \\\\/+\\*\\?\\(\\)\\[\\]\\{\\}:,]",
"replace_char": "_"
},
"ExtractImage": {
"formats": [
"png",

View file

@ -33,16 +33,6 @@
"key": "publish",
"label": "Publish plugins",
"children": [
{
"type": "schema_template",
"name": "template_publish_plugin",
"template_data": [
{
"key": "ValidateContainers",
"label": "ValidateContainers"
}
]
},
{
"type": "dict",
"collapsible": true,
@ -108,6 +98,38 @@
}
]
},
{
"type": "schema_template",
"name": "template_publish_plugin",
"template_data": [
{
"key": "ValidateContainers",
"label": "ValidateContainers"
}
]
},
{
"type": "dict",
"collapsible": true,
"key": "ValidateNaming",
"label": "Validate naming of subsets and layers",
"children": [
{
"type": "label",
"label": "Subset cannot contain invalid characters or extract to file would fail"
},
{
"type": "text",
"key": "invalid_chars",
"label": "Regex pattern of invalid characters"
},
{
"type": "text",
"key": "replace_char",
"label": "Replacement character"
}
]
},
{
"type": "dict",
"collapsible": true,