Skip to content

validate_workfile_paths

ValidateWorkfilePaths

Bases: HoudiniInstancePlugin, OptionalPyblishPluginMixin

Validate workfile paths so they are absolute.

Source code in client/ayon_houdini/plugins/publish/validate_workfile_paths.py
14
15
16
17
18
19
20
21
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
class ValidateWorkfilePaths(
        plugin.HoudiniInstancePlugin, OptionalPyblishPluginMixin):
    """Validate workfile paths so they are absolute."""

    order = pyblish.api.ValidatorOrder
    families = ["workfile"]
    label = "Validate Workfile Paths"
    actions = [RepairAction]
    optional = True

    node_types = ["file", "alembic"]
    prohibited_vars = ["$HIP", "$JOB"]

    def process(self, instance):
        if not self.is_active(instance.data):
            return
        invalid = self.get_invalid()
        self.log.debug(
            "Checking node types: {}".format(", ".join(self.node_types)))
        self.log.debug(
            "Searching prohibited vars: {}".format(
                ", ".join(self.prohibited_vars)
            )
        )

        if invalid:
            all_container_vars = set()
            for param in invalid:
                value = param.unexpandedString()
                contained_vars = [
                    var for var in self.prohibited_vars
                    if var in value
                ]
                all_container_vars.update(contained_vars)

                self.log.error(
                    "Parm {} contains prohibited vars {}: {}".format(
                        param.path(),
                        ", ".join(contained_vars),
                        value)
                )

            message = (
                "Prohibited vars {} found in parameter values".format(
                    ", ".join(all_container_vars)
                )
            )
            raise PublishValidationError(message, title=self.label)

    @classmethod
    def get_invalid(cls):
        invalid = []
        for param, _ in hou.fileReferences():
            # it might return None for some reason
            if not param:
                continue
            # skip nodes we are not interested in
            if param.node().type().name() not in cls.node_types:
                continue

            if param.keyframes():
                # Calling `.unexpandedString()` below fails if param has
                # keyframes - so for now we will skip those params. These are
                # e.g. present in `filecache` nodes.
                continue

            if any(
                    v for v in cls.prohibited_vars
                    if v in param.unexpandedString()):
                invalid.append(param)

        return invalid

    @classmethod
    def repair(cls, instance):
        invalid = cls.get_invalid()
        for param in invalid:
            cls.log.info("Processing: {}".format(param.path()))
            cls.log.info("Replacing {} for {}".format(
                param.unexpandedString(),
                hou.text.expandString(param.unexpandedString())))
            param.set(hou.text.expandString(param.unexpandedString()))