From eeff080b170e451225b257ea61ced66716be143a Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Wed, 17 Jul 2024 10:34:52 +0200 Subject: [PATCH 1/2] add more options to get task for older representations --- .../plugins/load/global/play_in_rv.py | 105 ++++++++++++------ 1 file changed, 68 insertions(+), 37 deletions(-) diff --git a/client/ayon_openrv/plugins/load/global/play_in_rv.py b/client/ayon_openrv/plugins/load/global/play_in_rv.py index b5c4312..1678d78 100644 --- a/client/ayon_openrv/plugins/load/global/play_in_rv.py +++ b/client/ayon_openrv/plugins/load/global/play_in_rv.py @@ -3,10 +3,11 @@ import ayon_api from ayon_applications import ApplicationManager -from ayon_core.pipeline import load from ayon_core.lib.transcoding import ( IMAGE_EXTENSIONS, VIDEO_EXTENSIONS ) +from ayon_core.pipeline import load +from ayon_core.pipeline.load import LoadError from ayon_openrv.networking import RVConnector @@ -32,48 +33,78 @@ class PlayInRV(load.LoaderPlugin): def load(self, context, name, namespace, data): rvcon = RVConnector() - if not rvcon.is_connected: # get launch context variables - project_name = context["project"]["name"] - - task_entity = None - task_id = context["version"]["taskId"] - # could be published without task from Publisher - if task_id: - task_entity = ayon_api.get_task_by_id(project_name, task_id) - - folder_entity = context["folder"] - folder_path = folder_entity.get("path") - # check required for host launch - if not all([folder_path, task_entity]): - raise Exception(f"Missing context data: {folder_path = }, " - f"{task_entity = }") - + project_name, folder_path, task_name = ( + self._get_lauch_context(context) + ) # launch RV with context - ctx = { - "project_name": project_name, - "folder_path": folder_path, - "task_name": task_entity["name"] - } - app_manager = ApplicationManager() - openrv_app = app_manager.find_latest_available_variant_for_group("openrv") + openrv_app = app_manager.find_latest_available_variant_for_group( + "openrv" + ) if not openrv_app: - raise RuntimeError( - f"No configured OpenRV found in " - f"Applications. Ask admin to configure it " - f"in ayon+settings://applications/applications/openrv.\n" - f"Provide '-network' there as argument." + raise LoadError( + f"No configured OpenRV found in" + f" Applications. Ask admin to configure it" + f" in ayon+settings://applications/applications/openrv." + f"\nProvide '-network' there as argument." ) - openrv_app.launch(**ctx) + openrv_app.launch( + project_name=project_name, + folder_path=folder_path, + task_name=task_name + ) - repre_ext = context["representation"]["context"]["representation"] - _data = [{ - "objectName": repre_ext, + payload = json.dumps([{ + "objectName": context["representation"]["name"], "representation": context["representation"]["id"], - }] - payload = json.dumps(_data) - with rvcon: # this also retries the connection + }]) + # This also retries the connection + with rvcon: rvcon.send_event( - "ayon_load_container", payload, shall_return=False) + "ayon_load_container", + payload, + shall_return=False + ) + + def _get_lauch_context(self, context): + # get launch context variables + project_name = context["project"]["name"] + + folder_entity = context["folder"] + folder_path = folder_entity.get("path") + if not folder_path: + raise LoadError( + "Selected representation does not have available folder." + " It is not possible to start OpenRV." + ) + + task_entity = None + task_id = context["version"]["taskId"] + # could be published without task from Publisher + if task_id: + task_entity = ayon_api.get_task_by_id(project_name, task_id) + + if not task_entity: + repre_context = context["representation"]["context"] + task_info = repre_context.get("task") + task_name = None + if task_info: + if isinstance(task_info, str): + task_name = task_info + elif isinstance(task_info, dict): + task_name = task_info.get("name") + + if task_name: + task_entity = ayon_api.get_task_by_name( + project_name, folder_entity["id"], task_name + ) + + if task_entity: + return project_name, folder_path, task_entity["name"] + + raise LoadError( + "Selected representation does not have available task." + " It is not possible to start OpenRV." + ) From 63b3787aba3a37551feabdc516e838bb7026c52c Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Wed, 17 Jul 2024 11:14:37 +0200 Subject: [PATCH 2/2] removed unnecessary f-strings --- client/ayon_openrv/plugins/load/global/play_in_rv.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/client/ayon_openrv/plugins/load/global/play_in_rv.py b/client/ayon_openrv/plugins/load/global/play_in_rv.py index 1678d78..ae77c6c 100644 --- a/client/ayon_openrv/plugins/load/global/play_in_rv.py +++ b/client/ayon_openrv/plugins/load/global/play_in_rv.py @@ -45,10 +45,10 @@ def load(self, context, name, namespace, data): ) if not openrv_app: raise LoadError( - f"No configured OpenRV found in" - f" Applications. Ask admin to configure it" - f" in ayon+settings://applications/applications/openrv." - f"\nProvide '-network' there as argument." + "No configured OpenRV found in" + " Applications. Ask admin to configure it" + " in ayon+settings://applications/applications/openrv." + "\nProvide '-network' there as argument." ) openrv_app.launch( project_name=project_name,