Skip to content

create_editorial_package

CreateEditorialPackage

Bases: ResolveCreator

Create Editorial Package.

Source code in client/ayon_resolve/plugins/create/create_editorial_package.py
 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
 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
class CreateEditorialPackage(ResolveCreator):
    """Create Editorial Package."""

    identifier = "io.ayon.creators.resolve.editorial_pkg"
    label = "Editorial Package"
    product_type = "editorial_pkg"
    icon = "camera"
    defaults = ["Main"]

    def get_pre_create_attr_defs(self):
        """Plugin attribute definitions needed for creation.

        Returns:
            list[AbstractAttrDef]: Attribute definitions that can be tweaked
                for created instance.
        """
        return _CREATE_ATTR_DEFS

    def get_attr_defs_for_instance(self, instance):
        """Get attribute definitions for an instance.

        Args:
            instance (CreatedInstance): Instance for which to get
                attribute definitions.

        Returns:
            list[AbstractAttrDef]: Attribute definitions that can be tweaked
                for created instance.
        """
        return _CREATE_ATTR_DEFS

    def create(self, product_name, instance_data, pre_create_data):
        """Create a new editorial_pkg instance.

        Args:
            product_name (str): The product name
            instance_data (dict): The instance data.
            pre_create_data (dict): The pre_create context data.
        """
        super().create(product_name,
                       instance_data,
                       pre_create_data)

        current_timeline = lib.get_current_timeline()

        if not current_timeline:
            raise CreatorError("Make sure to have an active current timeline.")

        timeline_media_pool_item = lib.get_timeline_media_pool_item(
            current_timeline
        )

        instance_data["creator_attributes"] = {
            "review": pre_create_data["review"]
        }

        tag_metadata = {
            "publish": deepcopy(instance_data),
        }
        tag_metadata["publish"].update(
            get_editorial_publish_data(
                folder_path=instance_data["folderPath"],
                product_name=product_name
            )
        )
        tag_metadata["publish"]["label"] = current_timeline.GetName()

        timeline_media_pool_item.SetMetadata(
            constants.AYON_TAG_NAME, json.dumps(tag_metadata)
        )

        new_instance = CreatedInstance(
            self.product_type,
            product_name,
            tag_metadata["publish"],
            self,
        )
        new_instance.transient_data["timeline_pool_item"] = (
            timeline_media_pool_item)
        self._add_instance_to_context(new_instance)

    def collect_instances(self):
        """Collect all created instances from current timeline."""
        for media_pool_item in lib.iter_all_media_pool_clips():
            data = media_pool_item.GetMetadata(constants.AYON_TAG_NAME)
            if not data:
                continue

            try:
                data = json.loads(data)
            except json.JSONDecodeError:
                self.log.warning(
                    "Failed to parse json data from media pool item: %s",
                    media_pool_item.GetName()
                )
                continue

            # exclude all which are not productType editorial_pkg
            if (
                data.get("publish", {}).get("productType") != self.product_type
            ):
                continue

            publish_data = data["publish"]

            # add label into instance data in case it is missing in publish
            # data (legacy publish) or timeline was renamed.
            publish_data["label"] = media_pool_item.GetName()

            # TODO: backward compatibility for legacy workflow instances
            # add variant into instance data in case it is missing in publish
            # data
            if "variant" not in publish_data:
                product_name = publish_data["productName"]
                product_type = publish_data["productType"]
                publish_data["variant"] = product_name.split(product_type)[1]

            current_instance = CreatedInstance(
                self.product_type,
                publish_data["productName"],
                publish_data,
                self
            )

            current_instance.transient_data["timeline_pool_item"] = (
                media_pool_item)
            self._add_instance_to_context(current_instance)

    def update_instances(self, update_list):
        """Store changes of existing instances so they can be recollected.

        Args:
            update_list(List[UpdateData]): Gets list of tuples. Each item
                contain changed instance and it's changes.
        """

        for created_inst, _changes in update_list:
            media_pool_item = created_inst.transient_data[
                "timeline_pool_item"]
            data = media_pool_item.GetMetadata(constants.AYON_TAG_NAME)
            data = json.loads(data)

            data["publish"].update(created_inst.data_to_store())

            media_pool_item.SetMetadata(
                constants.AYON_TAG_NAME,
                json.dumps(data),
            )

    def remove_instances(self, instances):
        """Remove instance marker from track item.

        Args:
            instance(List[CreatedInstance]): Instance objects which should be
                removed.
        """
        for instance in instances:
            self._remove_instance_from_context(instance)
            media_pool_item = instance.transient_data["timeline_pool_item"]

            data = media_pool_item.GetMetadata(constants.AYON_TAG_NAME)
            data = json.loads(data)

            # only removing publishing data since loading data has to remain
            data["publish"] = {}

            media_pool_item.SetMetadata(
                constants.AYON_TAG_NAME,
                json.dumps(data),
            )

collect_instances()

Collect all created instances from current timeline.

Source code in client/ayon_resolve/plugins/create/create_editorial_package.py
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
def collect_instances(self):
    """Collect all created instances from current timeline."""
    for media_pool_item in lib.iter_all_media_pool_clips():
        data = media_pool_item.GetMetadata(constants.AYON_TAG_NAME)
        if not data:
            continue

        try:
            data = json.loads(data)
        except json.JSONDecodeError:
            self.log.warning(
                "Failed to parse json data from media pool item: %s",
                media_pool_item.GetName()
            )
            continue

        # exclude all which are not productType editorial_pkg
        if (
            data.get("publish", {}).get("productType") != self.product_type
        ):
            continue

        publish_data = data["publish"]

        # add label into instance data in case it is missing in publish
        # data (legacy publish) or timeline was renamed.
        publish_data["label"] = media_pool_item.GetName()

        # TODO: backward compatibility for legacy workflow instances
        # add variant into instance data in case it is missing in publish
        # data
        if "variant" not in publish_data:
            product_name = publish_data["productName"]
            product_type = publish_data["productType"]
            publish_data["variant"] = product_name.split(product_type)[1]

        current_instance = CreatedInstance(
            self.product_type,
            publish_data["productName"],
            publish_data,
            self
        )

        current_instance.transient_data["timeline_pool_item"] = (
            media_pool_item)
        self._add_instance_to_context(current_instance)

create(product_name, instance_data, pre_create_data)

Create a new editorial_pkg instance.

Parameters:

Name Type Description Default
product_name str

The product name

required
instance_data dict

The instance data.

required
pre_create_data dict

The pre_create context data.

required
Source code in client/ayon_resolve/plugins/create/create_editorial_package.py
 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
def create(self, product_name, instance_data, pre_create_data):
    """Create a new editorial_pkg instance.

    Args:
        product_name (str): The product name
        instance_data (dict): The instance data.
        pre_create_data (dict): The pre_create context data.
    """
    super().create(product_name,
                   instance_data,
                   pre_create_data)

    current_timeline = lib.get_current_timeline()

    if not current_timeline:
        raise CreatorError("Make sure to have an active current timeline.")

    timeline_media_pool_item = lib.get_timeline_media_pool_item(
        current_timeline
    )

    instance_data["creator_attributes"] = {
        "review": pre_create_data["review"]
    }

    tag_metadata = {
        "publish": deepcopy(instance_data),
    }
    tag_metadata["publish"].update(
        get_editorial_publish_data(
            folder_path=instance_data["folderPath"],
            product_name=product_name
        )
    )
    tag_metadata["publish"]["label"] = current_timeline.GetName()

    timeline_media_pool_item.SetMetadata(
        constants.AYON_TAG_NAME, json.dumps(tag_metadata)
    )

    new_instance = CreatedInstance(
        self.product_type,
        product_name,
        tag_metadata["publish"],
        self,
    )
    new_instance.transient_data["timeline_pool_item"] = (
        timeline_media_pool_item)
    self._add_instance_to_context(new_instance)

get_attr_defs_for_instance(instance)

Get attribute definitions for an instance.

Parameters:

Name Type Description Default
instance CreatedInstance

Instance for which to get attribute definitions.

required

Returns:

Type Description

list[AbstractAttrDef]: Attribute definitions that can be tweaked for created instance.

Source code in client/ayon_resolve/plugins/create/create_editorial_package.py
39
40
41
42
43
44
45
46
47
48
49
50
def get_attr_defs_for_instance(self, instance):
    """Get attribute definitions for an instance.

    Args:
        instance (CreatedInstance): Instance for which to get
            attribute definitions.

    Returns:
        list[AbstractAttrDef]: Attribute definitions that can be tweaked
            for created instance.
    """
    return _CREATE_ATTR_DEFS

get_pre_create_attr_defs()

Plugin attribute definitions needed for creation.

Returns:

Type Description

list[AbstractAttrDef]: Attribute definitions that can be tweaked for created instance.

Source code in client/ayon_resolve/plugins/create/create_editorial_package.py
30
31
32
33
34
35
36
37
def get_pre_create_attr_defs(self):
    """Plugin attribute definitions needed for creation.

    Returns:
        list[AbstractAttrDef]: Attribute definitions that can be tweaked
            for created instance.
    """
    return _CREATE_ATTR_DEFS

remove_instances(instances)

Remove instance marker from track item.

Parameters:

Name Type Description Default
instance(List[CreatedInstance])

Instance objects which should be removed.

required
Source code in client/ayon_resolve/plugins/create/create_editorial_package.py
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
def remove_instances(self, instances):
    """Remove instance marker from track item.

    Args:
        instance(List[CreatedInstance]): Instance objects which should be
            removed.
    """
    for instance in instances:
        self._remove_instance_from_context(instance)
        media_pool_item = instance.transient_data["timeline_pool_item"]

        data = media_pool_item.GetMetadata(constants.AYON_TAG_NAME)
        data = json.loads(data)

        # only removing publishing data since loading data has to remain
        data["publish"] = {}

        media_pool_item.SetMetadata(
            constants.AYON_TAG_NAME,
            json.dumps(data),
        )

update_instances(update_list)

Store changes of existing instances so they can be recollected.

Parameters:

Name Type Description Default
update_list(List[UpdateData])

Gets list of tuples. Each item contain changed instance and it's changes.

required
Source code in client/ayon_resolve/plugins/create/create_editorial_package.py
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
def update_instances(self, update_list):
    """Store changes of existing instances so they can be recollected.

    Args:
        update_list(List[UpdateData]): Gets list of tuples. Each item
            contain changed instance and it's changes.
    """

    for created_inst, _changes in update_list:
        media_pool_item = created_inst.transient_data[
            "timeline_pool_item"]
        data = media_pool_item.GetMetadata(constants.AYON_TAG_NAME)
        data = json.loads(data)

        data["publish"].update(created_inst.data_to_store())

        media_pool_item.SetMetadata(
            constants.AYON_TAG_NAME,
            json.dumps(data),
        )