Skip to content

validate_no_namespace

ValidateNoNamespace

Bases: MayaInstancePlugin, OptionalPyblishPluginMixin

Ensure the nodes don't have a namespace

Source code in client/ayon_maya/plugins/publish/validate_no_namespace.py
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
class ValidateNoNamespace(plugin.MayaInstancePlugin,
                          OptionalPyblishPluginMixin):
    """Ensure the nodes don't have a namespace"""

    order = ValidateContentsOrder
    families = ['model']
    label = 'No Namespaces'
    actions = [ayon_maya.api.action.SelectInvalidAction,
               RepairAction]
    optional = False

    @staticmethod
    def get_invalid(instance):
        nodes = cmds.ls(instance, long=True)
        return [node for node in nodes if get_namespace(node)]

    def process(self, instance):
        """Process all the nodes in the instance"""
        if not self.is_active(instance.data):
            return
        invalid = self.get_invalid(instance)

        if invalid:
            invalid_namespaces = {get_namespace(node) for node in invalid}
            raise PublishValidationError(
                message="Namespaces found:\n\n{0}".format(
                    _as_report_list(sorted(invalid_namespaces))
                ),
                title="Namespaces in model",
                description=(
                    "## Namespaces found in model\n"
                    "It is not allowed to publish a model that contains "
                    "namespaces."
                )
            )

    @classmethod
    def repair(cls, instance):
        """Remove all namespaces from the nodes in the instance"""

        invalid = cls.get_invalid(instance)

        # Iterate over the nodes by long to short names to iterate the lowest
        # in hierarchy nodes first. This way we avoid having renamed parents
        # before renaming children nodes
        for node in sorted(invalid, key=len, reverse=True):

            node_name = node.rsplit("|", 1)[-1]
            node_name_without_namespace = node_name.rsplit(":")[-1]
            cmds.rename(node, node_name_without_namespace)

process(instance)

Process all the nodes in the instance

Source code in client/ayon_maya/plugins/publish/validate_no_namespace.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def process(self, instance):
    """Process all the nodes in the instance"""
    if not self.is_active(instance.data):
        return
    invalid = self.get_invalid(instance)

    if invalid:
        invalid_namespaces = {get_namespace(node) for node in invalid}
        raise PublishValidationError(
            message="Namespaces found:\n\n{0}".format(
                _as_report_list(sorted(invalid_namespaces))
            ),
            title="Namespaces in model",
            description=(
                "## Namespaces found in model\n"
                "It is not allowed to publish a model that contains "
                "namespaces."
            )
        )

repair(instance) classmethod

Remove all namespaces from the nodes in the instance

Source code in client/ayon_maya/plugins/publish/validate_no_namespace.py
62
63
64
65
66
67
68
69
70
71
72
73
74
75
@classmethod
def repair(cls, instance):
    """Remove all namespaces from the nodes in the instance"""

    invalid = cls.get_invalid(instance)

    # Iterate over the nodes by long to short names to iterate the lowest
    # in hierarchy nodes first. This way we avoid having renamed parents
    # before renaming children nodes
    for node in sorted(invalid, key=len, reverse=True):

        node_name = node.rsplit("|", 1)[-1]
        node_name_without_namespace = node_name.rsplit(":")[-1]
        cmds.rename(node, node_name_without_namespace)