Skip to content

create_online

Creator of online files.

Online file retain their original name and use it as product name. To avoid conflicts, this creator checks if product with this name already exists under selected folder.

OnlineCreator

Bases: TrayPublishCreator

Creates instance from file and retains its original name.

Source code in client/ayon_traypublisher/plugins/create/create_online.py
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
97
class OnlineCreator(TrayPublishCreator):
    """Creates instance from file and retains its original name."""

    identifier = "io.ayon.creators.traypublisher.online"
    label = "Online"
    product_type = "online"
    product_base_type = "online"
    description = "Publish file retaining its original file name"
    extensions = [".mov", ".mp4", ".mxf", ".m4v", ".mpg", ".exr",
                  ".dpx", ".tif", ".png", ".jpg"]

    def get_detail_description(self):
        return """# Create file retaining its original file name.

        This will publish files using template helping to retain original
        file name and that file name is used as product name.

        Bz default it tries to guard against multiple publishes of the same
        file."""

    def get_icon(self):
        return "fa.file"

    def create(self, product_name, instance_data, pre_create_data):
        repr_file = pre_create_data.get("representation_file")
        if not repr_file:
            raise CreatorError("No files specified")

        files = repr_file.get("filenames")
        if not files:
            # this should never happen
            raise CreatorError("Missing files from representation")

        origin_basename = Path(files[0]).stem
        instance_data["originalBasename"] = origin_basename
        product_name = origin_basename

        # Pass pre-create attributes to instance creator attributes
        instance_data["creator_attributes"] = pre_create_data

        # Create new instance
        new_instance = CreatedInstance(self.product_type, product_name,
                                       instance_data, self)
        self._store_new_instance(new_instance)

    def get_instance_attr_defs(self):
        return self.get_pre_create_attr_defs()

    def get_pre_create_attr_defs(self):
        return [
            FileDef(
                "representation_file",
                folders=False,
                extensions=self.extensions,
                allow_sequences=True,
                single_item=True,
                label="Representation",
            ),
            BoolDef(
                "add_review_family",
                default=True,
                label="Review"
            )
        ]

    def get_product_name(
        self,
        project_name,
        folder_entity,
        task_entity,
        variant,
        host_name=None,
        instance=None,
        project_entity=None,
        product_type=None,
    ):
        if instance is None:
            return "{originalBasename}"

        return instance.data["productName"]