Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3160 from pypeclub/bugfix/develop_OP-3137_Webpubl…
Browse files Browse the repository at this point in the history
…isher-replace-space-by-underscore-in-subset-names

Webpublisher: replace space by underscore in subset names
  • Loading branch information
kalisp authored May 11, 2022
2 parents 368b1b3 + edef0cc commit e92b530
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 7 deletions.
10 changes: 10 additions & 0 deletions openpype/hosts/photoshop/api/ws_stub.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ class PSItem(object):
color_code = attr.ib(default=None) # color code of layer
instance_id = attr.ib(default=None)

@property
def clean_name(self):
"""Returns layer name without publish icon highlight
Returns:
(str)
"""
return (self.name.replace(PhotoshopServerStub.PUBLISH_ICON, '')
.replace(PhotoshopServerStub.LOADED_ICON, ''))


class PhotoshopServerStub:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from openpype.lib import prepare_template_data
from openpype.hosts.photoshop import api as photoshop
from openpype.settings import get_project_settings


class CollectColorCodedInstances(pyblish.api.ContextPlugin):
Expand Down Expand Up @@ -49,6 +50,12 @@ def process(self, context):
asset_name = context.data["asset"]
task_name = context.data["task"]
variant = context.data["variant"]
project_name = context.data["projectEntity"]["name"]

naming_conventions = get_project_settings(project_name).get(
"photoshop", {}).get(
"publish", {}).get(
"ValidateNaming", {})

stub = photoshop.stub()
layers = stub.get_layers()
Expand Down Expand Up @@ -83,6 +90,9 @@ def process(self, context):
subset = resolved_subset_template.format(
**prepare_template_data(fill_pairs))

subset = self._clean_subset_name(stub, naming_conventions,
subset, layer)

if subset in existing_subset_names:
self.log.info(
"Subset {} already created, skipping.".format(subset))
Expand Down Expand Up @@ -141,6 +151,7 @@ def _create_instance(self, context, layer, family,
instance.data["task"] = task_name
instance.data["subset"] = subset
instance.data["layer"] = layer
instance.data["families"] = []

return instance

Expand Down Expand Up @@ -186,3 +197,21 @@ def _resolve_mapping(self, layer):
self.log.debug("resolved_subset_template {}".format(
resolved_subset_template))
return family, resolved_subset_template

def _clean_subset_name(self, stub, naming_conventions, subset, layer):
"""Cleans invalid characters from subset name and layer name."""
if re.search(naming_conventions["invalid_chars"], subset):
subset = re.sub(
naming_conventions["invalid_chars"],
naming_conventions["replace_char"],
subset
)
layer_name = re.sub(
naming_conventions["invalid_chars"],
naming_conventions["replace_char"],
layer.clean_name
)
layer.name = layer_name
stub.rename_layer(layer.id, layer_name)

return subset
19 changes: 12 additions & 7 deletions openpype/hosts/photoshop/plugins/publish/validate_naming.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def process(self, context, plugin):

layer_name = re.sub(invalid_chars,
replace_char,
current_layer_state.name)
current_layer_state.clean_name)
layer_name = stub.PUBLISH_ICON + layer_name

stub.rename_layer(current_layer_state.id, layer_name)

Expand Down Expand Up @@ -73,13 +74,17 @@ class ValidateNaming(pyblish.api.InstancePlugin):

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)

formatting_data = {"msg": msg}
if re.search(self.invalid_chars, instance.data["name"]):
raise PublishXmlValidationError(self, msg,
formatting_data=formatting_data)
layer = instance.data.get("layer")
if layer:
msg = "Name \"{}\" is not allowed.{}".format(layer.clean_name,
help_msg)

formatting_data = {"msg": msg}
if re.search(self.invalid_chars, layer.clean_name):
raise PublishXmlValidationError(self, msg,
formatting_data=formatting_data
)

msg = "Subset \"{}\" is not allowed.{}".format(instance.data["subset"],
help_msg)
Expand Down

0 comments on commit e92b530

Please sign in to comment.