Skip to content

collect_csv_ingest_instance_data

CollectCSVIngestInstancesData

Bases: InstancePlugin, AYONPyblishPluginMixin, ColormanagedPyblishPluginMixin

Collect CSV Ingest data from instance.

Source code in client/ayon_traypublisher/plugins/publish/collect_csv_ingest_instance_data.py
 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
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
class CollectCSVIngestInstancesData(
    pyblish.api.InstancePlugin,
    publish.AYONPyblishPluginMixin,
    publish.ColormanagedPyblishPluginMixin
):
    """Collect CSV Ingest data from instance."""

    label = "Collect CSV Ingest instances data"
    order = pyblish.api.CollectorOrder + 0.1
    hosts = ["traypublisher"]
    families = ["csv_ingest"]

    def process(self, instance):

        # populate all attributes to instance data
        self._process_passing_data(instance)

        # populate representation data to instance data
        self._process_representation_data(instance)

    def _process_representation_data(self, instance):
        """Populate representation data to instance data."""

        # expecting [(colorspace, repre_data), ...]
        prepared_repres_data_items = instance.data[
            "prepared_data_for_repres"]

        frame_start = None
        frame_end = None
        for prep_repre_data in prepared_repres_data_items:
            type = prep_repre_data["type"]
            colorspace = prep_repre_data["colorspace"]
            repre_data = prep_repre_data["representation"]

            # thumbnails should be skipped
            if type == "media":
                # colorspace name is passed from CSV column
                self.set_representation_colorspace(
                    repre_data, instance.context, colorspace
                )
            elif type == "media" and colorspace is None:
                # TODO: implement colorspace file rules file parsing
                self.log.warning(
                    "Colorspace is not defined in csv for following"
                    f" representation: {pformat(repre_data)}"
                )
                pass
            elif type == "thumbnail":
                # thumbnails should be skipped
                pass

            if (
                repre_data.get("tags") and
                "review" in repre_data.get("tags", [])
            ):
                if "frameStart" in repre_data and "frameEnd" in repre_data:
                    frame_start = repre_data["frameStart"]
                    frame_end = repre_data["frameEnd"]

            instance.data["representations"].append(repre_data)

        if frame_start is not None and frame_end is not None:
            instance.data["frameStart"] = frame_start
            instance.data["frameEnd"] = frame_end

    def _process_passing_data(self, instance):
        """Populate passing-data to instance data."""
        passing_data: list[PassingDataValue] = instance.data.get(
            "csv_passing_data", [])
        if not passing_data:
            return

        version_data = {}
        instance_data = {}
        for data_item in passing_data:
            key_name = data_item["name"]
            item_value = data_item["value"]
            data_type = data_item["data_type"]
            if data_type == "version_data":
                version_data[key_name] = item_value
            elif data_type == "instance_data":
                instance_data[key_name] = item_value

        if version_data:
            existing = instance.data.get("versionData") or {}
            existing.update(version_data)
            instance.data["versionData"] = existing
            for key, value in instance_data.items():
                instance.data[key] = value