Skip to content

context

Context

Bases: WorkflowTaskNode

Gather a valid AYON context item.

Source code in client/ayon_workflow/plugins/workflow/essentials/context.py
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
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
class Context(WorkflowTaskNode):
    """Gather a valid AYON context item."""

    version = "0.0.1"
    inputs = [
        InputAttribute(
            name="project_name",
            description="The project name",
        ),
        InputAttribute(
            name="folder_id",
            description="An optional folder ID.",
        ),
        InputAttribute(
            name="folder_path",
            description="An optional folder path.",
        ),
        InputAttribute(
            name="task_name",
            description="An optional task name.",
        ),
        InputAttribute(
            name="task_type",
            description="An optional task type.",
        ),
        InputAttribute(
            name="ensure_exists",
            description="Assert context existence.",
        ),
    ]
    outputs = [
        OutputAttribute(
            name="context",
            description="The resolved context.",
        )
    ]

    def execute(
        self,
        project_name: str,
        folder_id: Optional[str] = None,
        folder_path: Optional[str] = None,
        task_name: Optional[str] = None,
        task_type: Optional[str] = None,
        ensure_exists: Optional[bool] = True,
    ) -> ContextItem:
        if not project_name:
            raise ValueError("No project name provided.")

        if ensure_exists and (not ayon_api.get_project(project_name)):
            raise ValueError(f"Project {project_name} does not exist.")

        if folder_id or folder_path:
            folder_item = get_folder_item(
                project_name,
                folder_path=folder_path,
                folder_id=folder_id,
                ensure_exists=ensure_exists,
            )
            if task_name:
                return get_task_item(
                    project_name,
                    folder_item,
                    task_name,
                    task_type=task_type,
                    ensure_exists=ensure_exists,
                )
            return folder_item

        return ProjectItem(project_name=project_name)