22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147 | class ValidateProductName(plugin.HoudiniInstancePlugin,
OptionalPyblishPluginMixin):
"""Validate Product name."""
families = ["staticMesh", "hda"]
label = "Validate Product Name"
order = ValidateContentsOrder + 0.1
actions = [FixProductNameAction, SelectInvalidAction]
optional = True
def process(self, instance):
if not self.is_active(instance.data):
return
invalid = self.get_invalid(instance)
if invalid:
raise PublishValidationError(
"See log for details. "
"Invalid ROP node: {0}".format(invalid[0].path())
)
@classmethod
def get_invalid(cls, instance):
rop_node = hou.node(instance.data["instance_node"])
# Check product name
folder_entity = instance.data["folderEntity"]
task_entity = instance.data["taskEntity"]
task_name = task_type = None
if task_entity:
task_name = task_entity["name"]
task_type = task_entity["taskType"]
product_name = get_product_name(
project_name=instance.context.data["projectName"],
task_name=task_name,
task_type=task_type,
host_name=instance.context.data["hostName"],
product_type=instance.data["productType"],
variant=instance.data["variant"],
dynamic_data={
"folder": {
"label": folder_entity["label"],
"name": folder_entity["name"],
},
# Backwards compatibility
"asset": folder_entity["name"],
},
)
if instance.data.get("productName") != product_name:
cls.log.error(
"Invalid product name on rop node '%s' should be '%s'.",
rop_node.path(), product_name
)
return [rop_node]
@classmethod
def repair(cls, instance):
rop_node = hou.node(instance.data["instance_node"])
# Check product name
folder_entity = instance.data["folderEntity"]
task_entity = instance.data["taskEntity"]
task_name = task_type = None
if task_entity:
task_name = task_entity["name"]
task_type = task_entity["taskType"]
product_name = get_product_name(
project_name=instance.context.data["projectName"],
task_name=task_name,
task_type=task_type,
host_name=instance.context.data["hostName"],
product_type=instance.data["productType"],
variant=instance.data["variant"],
dynamic_data={
"asset": folder_entity["name"],
"folder": {
"label": folder_entity["label"],
"name": folder_entity["name"]
}
}
)
instance.data["productName"] = product_name
rop_node.parm("AYON_productName").set(product_name)
cls.log.debug(
"Product name on rop node '%s' has been set to '%s'.",
rop_node.path(), product_name
)
@classmethod
def convert_attribute_values(
cls, create_context, instance
):
# Convert old class name `ValidateSubsetName` to new class name
# `ValidateProductName` in the instance data.
if not instance:
return
publish_attributes = instance.data.get("publish_attributes", {})
if not publish_attributes:
return
if (
"ValidateSubsetName" in publish_attributes
and "ValidateProductName" not in publish_attributes
):
cls.log.debug(
"Converted `ValidateSubsetName` -> `ValidateProductName` "
f"in publish attributes for {instance['productName']}"
)
# Until PR https://github.com/ynput/ayon-core/pull/1219 we can't
# use `publish_attributes` directly. We can't `pop()` the key
# either. Use this logic as soon as `ayon-houdini` requires an
# `ayon-core` version 1.1.7 or higher.
# publish_attributes["ValidateProductName"] = (
# publish_attributes.pop("ValidateSubsetName")
# )
publish_attributes._data["ValidateProductName"] = (
publish_attributes["ValidateSubsetName"]
)
|