Skip to content

extract_workfile

Extract work file.

ExtractWorkfile

Bases: Extractor

Extract and zip complete workfile folder into zip.

Source code in client/ayon_harmony/plugins/publish/extract_workfile.py
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
class ExtractWorkfile(publish.Extractor):
    """Extract and zip complete workfile folder into zip."""

    label = "Extract Workfile"
    hosts = ["harmony"]
    families = ["workfile"]

    def process(self, instance):
        """Plugin entry point."""
        staging_dir = self.staging_dir(instance)
        filepath = os.path.join(staging_dir, "{}.tpl".format(instance.name))
        src = os.path.dirname(instance.context.data["currentFile"])
        # handle too long paths on windows
        current_platform = platform.system().lower()
        if current_platform == "windows":
            src = fr"\\?\{src}"
            filepath = fr"\\?\{filepath}"
        self.log.info(f"Copying to {filepath}")
        shutil.copytree(src, filepath)

        # Prep representation.
        os.chdir(staging_dir)
        shutil.make_archive(
            f"{instance.name}",
            "zip",
            os.path.join(staging_dir, f"{instance.name}.tpl")
        )
        # Check if archive is ok
        with ZipFile(os.path.basename(f"{instance.name}.zip")) as zr:
            if zr.testzip() is not None:
                raise Exception("File archive is corrupted.")

        representation = {
            "name": "tpl",
            "ext": "zip",
            "files": f"{instance.name}.zip",
            "stagingDir": staging_dir
        }
        instance.data["representations"] = [representation]

process(instance)

Plugin entry point.

Source code in client/ayon_harmony/plugins/publish/extract_workfile.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
def process(self, instance):
    """Plugin entry point."""
    staging_dir = self.staging_dir(instance)
    filepath = os.path.join(staging_dir, "{}.tpl".format(instance.name))
    src = os.path.dirname(instance.context.data["currentFile"])
    # handle too long paths on windows
    current_platform = platform.system().lower()
    if current_platform == "windows":
        src = fr"\\?\{src}"
        filepath = fr"\\?\{filepath}"
    self.log.info(f"Copying to {filepath}")
    shutil.copytree(src, filepath)

    # Prep representation.
    os.chdir(staging_dir)
    shutil.make_archive(
        f"{instance.name}",
        "zip",
        os.path.join(staging_dir, f"{instance.name}.tpl")
    )
    # Check if archive is ok
    with ZipFile(os.path.basename(f"{instance.name}.zip")) as zr:
        if zr.testzip() is not None:
            raise Exception("File archive is corrupted.")

    representation = {
        "name": "tpl",
        "ext": "zip",
        "files": f"{instance.name}.zip",
        "stagingDir": staging_dir
    }
    instance.data["representations"] = [representation]