Skip to content

validate_filepaths

ValidateFilePath

Bases: InstancePlugin

Validate existence of source filepaths on instance.

Plugins looks into key 'sourceFilepaths' and validate if paths there actually exist on disk.

Also validate if the key is filled but is empty. In that case also crashes so do not fill the key if unfilled value should not cause error.

This is primarily created for Simple Creator instances.

Source code in client/ayon_traypublisher/plugins/publish/validate_filepaths.py
 6
 7
 8
 9
10
11
12
13
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
class ValidateFilePath(pyblish.api.InstancePlugin):
    """Validate existence of source filepaths on instance.

    Plugins looks into key 'sourceFilepaths' and validate if paths there
    actually exist on disk.

    Also validate if the key is filled but is empty. In that case also
    crashes so do not fill the key if unfilled value should not cause error.

    This is primarily created for Simple Creator instances.
    """

    label = "Validate Filepaths"
    order = pyblish.api.ValidatorOrder - 0.49

    hosts = ["traypublisher"]

    def process(self, instance):
        if "sourceFilepaths" not in instance.data:
            self.log.info((
                "Skipped validation of source filepaths existence."
                " Instance does not have collected 'sourceFilepaths'"
            ))
            return

        product_type = instance.data["productType"]
        label = instance.data["name"]
        filepaths = instance.data["sourceFilepaths"]
        if not filepaths:
            raise PublishValidationError(
                (
                    "Source filepaths of '{}' instance \"{}\" are not filled"
                ).format(product_type, label),
                "File not filled",
                (
                    "## Files were not filled"
                    "\nThis mean that you didn't enter any files into required"
                    " file input."
                    "\n- Please refresh publishing and check instance"
                    " <b>{}</b>"
                ).format(label)
            )

        not_found_files = [
            filepath
            for filepath in filepaths
            if not os.path.exists(filepath)
        ]
        if not_found_files:
            joined_paths = "\n".join([
                "- {}".format(filepath)
                for filepath in not_found_files
            ])
            raise PublishValidationError(
                (
                    "Filepath of '{}' instance \"{}\" does not exist:\n{}"
                ).format(product_type, label, joined_paths),
                "File not found",
                (
                    "## Files were not found\nFiles\n{}"
                    "\n\nCheck if the path is still available."
                ).format(joined_paths)
            )