From 737a485530bbac1960ad4fe93bb381daea4cc956 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Tue, 4 Jan 2022 17:59:58 +0100 Subject: [PATCH] flame: fix passing env var and flame version dynamic filling --- .../hosts/flame/api/scripts/wiretap_com.py | 17 +++++++++----- openpype/hosts/flame/hooks/pre_flame_setup.py | 23 +++++++++++++------ .../system_settings/applications.json | 8 ++++--- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/openpype/hosts/flame/api/scripts/wiretap_com.py b/openpype/hosts/flame/api/scripts/wiretap_com.py index d8dc1884cf..5f7b2580e6 100644 --- a/openpype/hosts/flame/api/scripts/wiretap_com.py +++ b/openpype/hosts/flame/api/scripts/wiretap_com.py @@ -10,14 +10,19 @@ import xml.dom.minidom as minidom from copy import deepcopy import datetime +FLAME_V = os.getenv("OPENPYPE_FLAME_VERSION") + +if not FLAME_V: + raise KeyError("Missing key in environment `OPENPYPE_FLAME_VERSION`") + try: from libwiretapPythonClientAPI import ( WireTapClientInit) except ImportError: - flame_python_path = "/opt/Autodesk/flame_2021/python" + flame_python_path = "/opt/Autodesk/flame_{}/python".format(FLAME_V) flame_exe_path = ( - "/opt/Autodesk/flame_2021/bin/flame.app" - "/Contents/MacOS/startApp") + "/opt/Autodesk/flame_{}/bin/flame.app" + "/Contents/MacOS/startApp").format(FLAME_V) sys.path.append(flame_python_path) @@ -169,7 +174,7 @@ class WireTapCom(object): # check if volumes exists if self.volume_name not in volumes: raise AttributeError( - ("Volume '{}' does not exist '{}'").format( + ("Volume '{}' does not exist in '{}'").format( self.volume_name, volumes) ) @@ -179,7 +184,7 @@ class WireTapCom(object): "/opt/Autodesk/", "wiretap", "tools", - "2021", + FLAME_V, "wiretap_create_node", ), '-n', @@ -434,7 +439,7 @@ class WireTapCom(object): "/opt/Autodesk/", "wiretap", "tools", - "2021", + FLAME_V, "wiretap_duplicate_node", ), "-s", diff --git a/openpype/hosts/flame/hooks/pre_flame_setup.py b/openpype/hosts/flame/hooks/pre_flame_setup.py index 159fb37410..e7ef856907 100644 --- a/openpype/hosts/flame/hooks/pre_flame_setup.py +++ b/openpype/hosts/flame/hooks/pre_flame_setup.py @@ -19,7 +19,10 @@ class FlamePrelaunch(PreLaunchHook): app_groups = ["flame"] # todo: replace version number with avalon launch app version - flame_python_exe = "/opt/Autodesk/python/2021/bin/python2.7" + flame_python_exe = ( + "/opt/Autodesk/python/{OPENPYPE_FLAME_VERSION}" + "/bin/python2.7" + ) wtc_script_path = os.path.join( opflame.HOST_DIR, "api", "scripts", "wiretap_com.py") @@ -30,6 +33,7 @@ class FlamePrelaunch(PreLaunchHook): self.signature = "( {} )".format(self.__class__.__name__) def execute(self): + _env = self.launch_context.env """Hook entry method.""" project_doc = self.data["project_doc"] user_name = get_openpype_username() @@ -58,9 +62,9 @@ class FlamePrelaunch(PreLaunchHook): data_to_script = { # from settings - "host_name": os.getenv("FLAME_WIRETAP_HOSTNAME") or hostname, - "volume_name": os.getenv("FLAME_WIRETAP_VOLUME"), - "group_name": os.getenv("FLAME_WIRETAP_GROUP"), + "host_name": _env.get("FLAME_WIRETAP_HOSTNAME") or hostname, + "volume_name": _env.get("FLAME_WIRETAP_VOLUME"), + "group_name": _env.get("FLAME_WIRETAP_GROUP"), "color_policy": "ACES 1.1", # from project @@ -68,9 +72,12 @@ class FlamePrelaunch(PreLaunchHook): "user_name": user_name, "project_data": project_data } + + self.log.info(pformat(dict(_env))) + self.log.info(pformat(data_to_script)) + app_arguments = self._get_launch_arguments(data_to_script) - self.log.info(pformat(dict(self.launch_context.env))) opflame.setup(self.launch_context.env) @@ -83,7 +90,9 @@ class FlamePrelaunch(PreLaunchHook): with make_temp_file(dumped_script_data) as tmp_json_path: # Prepare subprocess arguments args = [ - self.flame_python_exe, + self.flame_python_exe.format( + **self.launch_context.env + ), self.wtc_script_path, tmp_json_path ] @@ -91,7 +100,7 @@ class FlamePrelaunch(PreLaunchHook): process_kwargs = { "logger": self.log, - "env": {} + "env": self.launch_context.env } openpype.api.run_subprocess(args, **process_kwargs) diff --git a/openpype/settings/defaults/system_settings/applications.json b/openpype/settings/defaults/system_settings/applications.json index 1cbe09f576..23ea64fdc1 100644 --- a/openpype/settings/defaults/system_settings/applications.json +++ b/openpype/settings/defaults/system_settings/applications.json @@ -118,10 +118,10 @@ "executables": { "windows": [], "darwin": [ - "/opt/Autodesk/flame_2021/bin/flame.app/Contents/MacOS/startApp" + "/opt/Autodesk/flame_{OPENPYPE_FLAME_VERSION}/bin/flame.app/Contents/MacOS/startApp" ], "linux": [ - "/opt/Autodesk/flame_2021/bin/flame" + "/opt/Autodesk/flame_{OPENPYPE_FLAME_VERSION}/bin/flame" ] }, "arguments": { @@ -129,7 +129,9 @@ "darwin": [], "linux": [] }, - "environment": {} + "environment": { + "OPENPYPE_FLAME_VERSION": "2021" + } }, "__dynamic_keys_labels__": { "2021": "2021 (Testing Only)"