From 394186bfb89259f2cb66f8fc516335d7e74447b4 Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Fri, 8 Mar 2024 17:32:42 +0100 Subject: [PATCH] use more suitable functions to get context data --- client/ayon_core/hosts/nuke/api/lib.py | 4 ++-- client/ayon_core/pipeline/colorspace.py | 4 ++-- client/ayon_core/pipeline/context_tools.py | 23 ++++++++++++++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/client/ayon_core/hosts/nuke/api/lib.py b/client/ayon_core/hosts/nuke/api/lib.py index 374a4608fc..8e39475f10 100644 --- a/client/ayon_core/hosts/nuke/api/lib.py +++ b/client/ayon_core/hosts/nuke/api/lib.py @@ -41,7 +41,7 @@ from ayon_core.pipeline import ( AVALON_INSTANCE_ID, ) from ayon_core.pipeline.context_tools import ( - get_custom_workfile_template_from_session + get_current_context_custom_workfile_template ) from ayon_core.pipeline.colorspace import get_imageio_config from ayon_core.pipeline.workfile import BuildWorkfile @@ -2458,7 +2458,7 @@ def process_workfile_builder(): # generate first version in file not existing and feature is enabled if create_fv_on and not os.path.exists(last_workfile_path): # get custom template path if any - custom_template_path = get_custom_workfile_template_from_session( + custom_template_path = get_current_context_custom_workfile_template( project_settings=project_settings ) diff --git a/client/ayon_core/pipeline/colorspace.py b/client/ayon_core/pipeline/colorspace.py index 7100984217..034c90d27b 100644 --- a/client/ayon_core/pipeline/colorspace.py +++ b/client/ayon_core/pipeline/colorspace.py @@ -774,8 +774,8 @@ def get_imageio_config( if not anatomy_data: from ayon_core.pipeline.context_tools import ( - get_template_data_from_session) - anatomy_data = get_template_data_from_session() + get_current_context_template_data) + anatomy_data = get_current_context_template_data() formatting_data = deepcopy(anatomy_data) diff --git a/client/ayon_core/pipeline/context_tools.py b/client/ayon_core/pipeline/context_tools.py index cc5acd810c..50c384bf88 100644 --- a/client/ayon_core/pipeline/context_tools.py +++ b/client/ayon_core/pipeline/context_tools.py @@ -590,6 +590,29 @@ def get_custom_workfile_template_from_session( ) +def get_current_context_custom_workfile_template(project_settings=None): + """Filter and fill workfile template profiles by current context. + + This function can be used only inside host where context is set. + + Args: + project_settings(Optional[Dict[str, Any]]): Project settings. + + Returns: + str: Path to template or None if none of profiles match current + context. (Existence of formatted path is not validated.) + + """ + context = get_current_context() + return get_custom_workfile_template_by_string_context( + context["project_name"], + context["folder_path"], + context["task_name"], + get_current_host_name(), + project_settings=project_settings + ) + + def change_current_context(folder_entity, task_entity, template_key=None): """Update active Session to a new task work area.