From 43a96ceb2abf0763314f24483bbbb088a2b8722b Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Mon, 4 Mar 2024 15:38:33 +0100 Subject: [PATCH] applications launch context has folder and task entity --- .../hooks/pre_copy_template_workfile.py | 13 +++---- .../ayon_core/hooks/pre_global_host_data.py | 30 ++++++++++++---- client/ayon_core/hooks/pre_ocio_hook.py | 2 +- .../celaction/hooks/pre_celaction_setup.py | 6 ++-- .../unreal/hooks/pre_workfile_preparation.py | 2 +- client/ayon_core/lib/applications.py | 35 ++++++++++--------- client/ayon_core/lib/path_tools.py | 2 +- .../launch_hooks/post_start_timer.py | 6 ++-- 8 files changed, 58 insertions(+), 38 deletions(-) diff --git a/client/ayon_core/hooks/pre_copy_template_workfile.py b/client/ayon_core/hooks/pre_copy_template_workfile.py index 13f2f64565..096ad7dd7e 100644 --- a/client/ayon_core/hooks/pre_copy_template_workfile.py +++ b/client/ayon_core/hooks/pre_copy_template_workfile.py @@ -54,21 +54,22 @@ class CopyTemplateWorkfile(PreLaunchHook): self.log.info("Last workfile does not exist.") project_name = self.data["project_name"] - asset_name = self.data["folder_path"] + folder_path = self.data["folder_path"] task_name = self.data["task_name"] host_name = self.application.host_name project_settings = get_project_settings(project_name) project_entity = self.data.get("project_entity") - asset_doc = self.data.get("asset_doc") + folder_entity = self.data.get("folder_entity") + task_entity = self.data.get("task_entity") anatomy = self.data.get("anatomy") - if project_entity and asset_doc: + if project_entity and folder_entity and task_entity: self.log.debug("Started filtering of custom template paths.") template_path = get_custom_workfile_template( project_entity, - asset_doc, - task_name, + folder_entity, + task_entity, host_name, anatomy, project_settings @@ -81,7 +82,7 @@ class CopyTemplateWorkfile(PreLaunchHook): )) template_path = get_custom_workfile_template_by_string_context( project_name, - asset_name, + folder_path, task_name, host_name, anatomy, diff --git a/client/ayon_core/hooks/pre_global_host_data.py b/client/ayon_core/hooks/pre_global_host_data.py index b6cfe2d5d4..27e66450ab 100644 --- a/client/ayon_core/hooks/pre_global_host_data.py +++ b/client/ayon_core/hooks/pre_global_host_data.py @@ -1,4 +1,4 @@ -from ayon_api import get_project, get_folder_by_path +from ayon_api import get_project, get_folder_by_path, get_task_by_name from ayon_core.lib.applications import ( PreLaunchHook, @@ -17,7 +17,7 @@ class GlobalHostDataHook(PreLaunchHook): """Prepare global objects to `data` that will be used for sure.""" self.prepare_global_data() - if not self.data.get("asset_doc"): + if not self.data.get("folder_entity"): return app = self.launch_context.application @@ -29,7 +29,8 @@ class GlobalHostDataHook(PreLaunchHook): "app": app, "project_entity": self.data["project_entity"], - "asset_doc": self.data["asset_doc"], + "folder_entity": self.data["folder_entity"], + "task_entity": self.data["task_entity"], "anatomy": self.data["anatomy"], @@ -70,12 +71,27 @@ class GlobalHostDataHook(PreLaunchHook): project_name, project_entity=project_entity ) - asset_name = self.data.get("folder_path") - if not asset_name: + folder_path = self.data.get("folder_path") + if not folder_path: self.log.warning( - "Asset name was not set. Skipping asset document query." + "Folder path is not set. Skipping folder query." ) return - folder_entity = get_folder_by_path(project_name, asset_name) + folder_entity = get_folder_by_path(project_name, folder_path) self.data["folder_entity"] = folder_entity + + task_name = self.data.get("task_name") + if not task_name: + self.log.warning( + "Task name is not set. Skipping task query." + ) + return + + if not folder_entity: + return + + task_entity = get_task_by_name( + project_name, folder_entity["id"], task_name + ) + self.data["task_entity"] = task_entity \ No newline at end of file diff --git a/client/ayon_core/hooks/pre_ocio_hook.py b/client/ayon_core/hooks/pre_ocio_hook.py index 08d9563975..e135a5bb12 100644 --- a/client/ayon_core/hooks/pre_ocio_hook.py +++ b/client/ayon_core/hooks/pre_ocio_hook.py @@ -28,7 +28,7 @@ class OCIOEnvHook(PreLaunchHook): template_data = get_template_data_with_names( project_name=self.data["project_name"], - asset_name=self.data["folder_path"], + folder_path=self.data["folder_path"], task_name=self.data["task_name"], host_name=self.host_name, settings=self.data["project_settings"] diff --git a/client/ayon_core/hosts/celaction/hooks/pre_celaction_setup.py b/client/ayon_core/hosts/celaction/hooks/pre_celaction_setup.py index bf1b4937cd..73b368e4e3 100644 --- a/client/ayon_core/hosts/celaction/hooks/pre_celaction_setup.py +++ b/client/ayon_core/hosts/celaction/hooks/pre_celaction_setup.py @@ -16,9 +16,9 @@ class CelactionPrelaunchHook(PreLaunchHook): launch_types = {LaunchTypes.local} def execute(self): - asset_doc = self.data["asset_doc"] - width = asset_doc["data"]["resolutionWidth"] - height = asset_doc["data"]["resolutionHeight"] + folder_attributes = self.data["folder_entity"]["attrib"] + width = folder_attributes["resolutionWidth"] + height = folder_attributes["resolutionHeight"] # Add workfile path to launch arguments workfile_path = self.workfile_path() diff --git a/client/ayon_core/hosts/unreal/hooks/pre_workfile_preparation.py b/client/ayon_core/hosts/unreal/hooks/pre_workfile_preparation.py index a8feaa31d8..2f78bf026d 100644 --- a/client/ayon_core/hosts/unreal/hooks/pre_workfile_preparation.py +++ b/client/ayon_core/hosts/unreal/hooks/pre_workfile_preparation.py @@ -61,9 +61,9 @@ class UnrealPrelaunchHook(PreLaunchHook): # Get workfile template key for current context workfile_template_key = get_workfile_template_key( + project_entity["name"], task_type, self.host_name, - project_name=project_entity["name"] ) # Fill templates template_obj = anatomy.templates_obj[workfile_template_key]["file"] diff --git a/client/ayon_core/lib/applications.py b/client/ayon_core/lib/applications.py index 866a616518..e67f996bab 100644 --- a/client/ayon_core/lib/applications.py +++ b/client/ayon_core/lib/applications.py @@ -12,7 +12,6 @@ from abc import ABCMeta, abstractmethod import six from ayon_core import AYON_CORE_ROOT -from ayon_core.client import get_asset_name_identifier from ayon_core.settings import get_project_settings, get_studio_settings from .log import Logger from .profiles_filtering import filter_profiles @@ -1381,7 +1380,7 @@ class EnvironmentPrepData(dict): data (dict): Data must contain required keys. """ required_keys = ( - "project_entity", "asset_doc", "task_name", "app", "anatomy" + "project_entity", "folder_entity", "task_name", "app", "anatomy" ) def __init__(self, data): @@ -1546,13 +1545,13 @@ def prepare_app_environments( app.environment ] - asset_doc = data.get("asset_doc") + folder_entity = data.get("folder_entity") # Add tools environments groups_by_name = {} tool_by_group_name = collections.defaultdict(dict) - if asset_doc: + if folder_entity: # Make sure each tool group can be added only once - for key in asset_doc["data"].get("tools_env") or []: + for key in folder_entity["attrib"].get("tools") or []: tool = app.manager.tools.get(key) if not tool or not tool.is_valid_for_app(app): continue @@ -1675,8 +1674,8 @@ def prepare_context_environments(data, env_group=None, addons_manager=None): log = data["log"] project_entity = data["project_entity"] - asset_doc = data["asset_doc"] - task_name = data["task_name"] + folder_entity = data["folder_entity"] + task_entity = data["task_entity"] if not project_entity: log.info( "Skipping context environments preparation." @@ -1694,12 +1693,12 @@ def prepare_context_environments(data, env_group=None, addons_manager=None): "AYON_PROJECT_NAME": project_entity["name"], "AYON_APP_NAME": app.full_name } - if asset_doc: - asset_name = get_asset_name_identifier(asset_doc) - context_env["AYON_FOLDER_PATH"] = asset_name + if folder_entity: + folder_path = folder_entity["path"] + context_env["AYON_FOLDER_PATH"] = folder_path - if task_name: - context_env["AYON_TASK_NAME"] = task_name + if task_entity: + context_env["AYON_TASK_NAME"] = task_entity["name"] log.debug( "Context environments set:\n{}".format( @@ -1719,15 +1718,19 @@ def prepare_context_environments(data, env_group=None, addons_manager=None): data["env"]["AYON_HOST_NAME"] = app.host_name - if not asset_doc or not task_name: + if not folder_entity or not task_entity: # QUESTION replace with log.info and skip workfile discovery? # - technically it should be possible to launch host without context raise ApplicationLaunchFailed( - "Host launch require asset and task context." + "Host launch require folder and task context." ) workdir_data = get_template_data( - project_entity, asset_doc, task_name, app.host_name, project_settings + project_entity, + folder_entity, + task_entity, + app.host_name, + project_settings ) data["workdir_data"] = workdir_data @@ -1853,9 +1856,9 @@ def _prepare_last_workfile(data, workdir, addons_manager): project_settings = data["project_settings"] task_type = workdir_data["task"]["type"] template_key = get_workfile_template_key( + project_name, task_type, app.host_name, - project_name, project_settings=project_settings ) # Find last workfile diff --git a/client/ayon_core/lib/path_tools.py b/client/ayon_core/lib/path_tools.py index fec6a0c47d..74475adfe3 100644 --- a/client/ayon_core/lib/path_tools.py +++ b/client/ayon_core/lib/path_tools.py @@ -78,7 +78,7 @@ def collect_frames(files): files(list) or (set with single value): list of source paths Returns: - (dict): {'/asset/subset_v001.0001.png': '0001', ....} + dict: {'/folder/subset_v001.0001.png': '0001', ....} """ patterns = [clique.PATTERNS["frames"]] diff --git a/client/ayon_core/modules/timers_manager/launch_hooks/post_start_timer.py b/client/ayon_core/modules/timers_manager/launch_hooks/post_start_timer.py index 4e94603aa9..da5d430939 100644 --- a/client/ayon_core/modules/timers_manager/launch_hooks/post_start_timer.py +++ b/client/ayon_core/modules/timers_manager/launch_hooks/post_start_timer.py @@ -11,13 +11,13 @@ class PostStartTimerHook(PostLaunchHook): def execute(self): project_name = self.data.get("project_name") - asset_name = self.data.get("folder_path") + folder_path = self.data.get("folder_path") task_name = self.data.get("task_name") missing_context_keys = set() if not project_name: missing_context_keys.add("project_name") - if not asset_name: + if not folder_path: missing_context_keys.add("folder_path") if not task_name: missing_context_keys.add("task_name") @@ -40,5 +40,5 @@ class PostStartTimerHook(PostLaunchHook): return timers_manager.start_timer_with_webserver( - project_name, asset_name, task_name, logger=self.log + project_name, folder_path, task_name, logger=self.log )