Skip to content

load_template

Load template.

TemplateLoader

Bases: BackdropBaseLoader

Load Harmony template as Backdrop container.

Source code in client/ayon_harmony/plugins/load/load_template.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
50
51
52
53
54
55
56
class TemplateLoader(harmony.BackdropBaseLoader):
    """Load Harmony template as Backdrop container."""

    product_types = {"harmony.template"}
    representations = {"tpl"}
    label = "Load Template"
    icon = "gift"

    def load(self, context, name=None, namespace=None, data=None):
        """Plugin entry point.

        Args:
            context (:class:`pyblish.api.Context`): Context.
            name (str, optional): Container name.
            namespace (str, optional): Container namespace.
            data (dict, optional): Additional data passed into loader.

        """
        # Load template.
        self_name = self.__class__.__name__
        temp_dir = tempfile.mkdtemp()
        zip_file = self.filepath_from_context(context)

        with zipfile.ZipFile(zip_file, "r") as zip_ref:
            zip_ref.extractall(temp_dir)

        backdrop_name = harmony.send(
            {
                "function": f"AyonHarmony.Loaders.{self_name}.loadContainer",
                # Published tpl name is not consistent, use first found,
                #   must be only one
                "args": next(Path(temp_dir).glob("*.tpl")).as_posix(),
            }
        )["result"]

        # Cleanup the temp directory
        shutil.rmtree(temp_dir)

        # We must validate the group_node
        return harmony.containerise(
            name,
            namespace,
            backdrop_name,
            context,
            self_name
        )

load(context, name=None, namespace=None, data=None)

Plugin entry point.

Parameters:

Name Type Description Default
context (

class:pyblish.api.Context): Context.

required
name str

Container name.

None
namespace str

Container namespace.

None
data dict

Additional data passed into loader.

None
Source code in client/ayon_harmony/plugins/load/load_template.py
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
def load(self, context, name=None, namespace=None, data=None):
    """Plugin entry point.

    Args:
        context (:class:`pyblish.api.Context`): Context.
        name (str, optional): Container name.
        namespace (str, optional): Container namespace.
        data (dict, optional): Additional data passed into loader.

    """
    # Load template.
    self_name = self.__class__.__name__
    temp_dir = tempfile.mkdtemp()
    zip_file = self.filepath_from_context(context)

    with zipfile.ZipFile(zip_file, "r") as zip_ref:
        zip_ref.extractall(temp_dir)

    backdrop_name = harmony.send(
        {
            "function": f"AyonHarmony.Loaders.{self_name}.loadContainer",
            # Published tpl name is not consistent, use first found,
            #   must be only one
            "args": next(Path(temp_dir).glob("*.tpl")).as_posix(),
        }
    )["result"]

    # Cleanup the temp directory
    shutil.rmtree(temp_dir)

    # We must validate the group_node
    return harmony.containerise(
        name,
        namespace,
        backdrop_name,
        context,
        self_name
    )