Skip to content

increment_workfile

IncrementWorkfile

Bases: InstancePlugin

Increment the current workfile.

Saves the current scene with an increased version number in both local unzipped folder and creates zipped file in work area.

Marks current unzipped folder with lower version to be deleted afterwards. It should be obsolete as it is fully copied to incremented folder.

Source code in client/ayon_harmony/plugins/publish/increment_workfile.py
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
class IncrementWorkfile(pyblish.api.InstancePlugin):
    """Increment the current workfile.

    Saves the current scene with an increased version number in both
    local unzipped folder and creates zipped file in `work` area.

    Marks current unzipped folder with lower version to be deleted afterwards.
    It should be obsolete as it is fully copied to incremented folder.
    """

    label = "Increment Workfile"
    order = pyblish.api.IntegratorOrder + 9.0
    hosts = ["harmony"]
    families = ["workfile"]
    optional = True

    def process(self, instance):
        errored_plugins = get_errored_plugins_from_context(instance.context)
        if errored_plugins:
            raise RuntimeError(
                "Skipping incrementing current file because publishing failed."
            )

        context = instance.context
        host: IWorkfileHost = registered_host()

        current_filepath: str = context.data["currentFile"]

        current_filename = os.path.basename(current_filepath)
        current_local_dir = os.path.dirname(current_filepath)
        save_next_version(
            description=(
                f"Incremented by publishing from {current_filename}"
            ),
            # Optimize the save by reducing needed queries for context
            prepared_data=SaveWorkfileOptionalData(
                project_entity=context.data["projectEntity"],
                project_settings=context.data["project_settings"],
                anatomy=context.data["anatomy"],
            )
        )
        new_scene_path = host.get_current_workfile()

        # Mark unzipped temp workfile to be deleted
        instance.context.data["cleanupFullPaths"].append(current_local_dir)

        self.log.info("Incremented workfile to: {}".format(new_scene_path))