From 3e096f41bedfff6e8cd39c482ce64aac55da1766 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 14 Dec 2021 18:00:07 +0100 Subject: [PATCH] added helper function to return linux app launcher arguments --- openpype/lib/__init__.py | 2 ++ openpype/lib/execute.py | 46 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/openpype/lib/__init__.py b/openpype/lib/__init__.py index efd2cddf7e..936ee9ea8d 100644 --- a/openpype/lib/__init__.py +++ b/openpype/lib/__init__.py @@ -25,6 +25,7 @@ from .env_tools import ( from .terminal import Terminal from .execute import ( get_pype_execute_args, + get_linux_launcher_args, execute, run_subprocess, path_to_subprocess_arg, @@ -174,6 +175,7 @@ terminal = Terminal __all__ = [ "get_pype_execute_args", + "get_linux_launcher_args", "execute", "run_subprocess", "path_to_subprocess_arg", diff --git a/openpype/lib/execute.py b/openpype/lib/execute.py index ad77b2f899..a36a1f0bf4 100644 --- a/openpype/lib/execute.py +++ b/openpype/lib/execute.py @@ -1,7 +1,6 @@ import os -import shlex import subprocess -import platform +import distutils.spawn from .log import PypeLogger as Logger @@ -175,3 +174,46 @@ def get_pype_execute_args(*args): pype_args.extend(args) return pype_args + + +def get_linux_launcher_args(*args): + """Path to application mid process executable. + + This function should be able as arguments are different when used + from code and build. + + It is possible that this function is used in OpenPype build which does + not have yet the new executable. In that case 'None' is returned. + + Args: + args (iterable): List of additional arguments added after executable + argument. + + Returns: + list: Executables with possible positional argument to script when + called from code. + """ + filename = "linux_app_launcher" + openpype_executable = os.environ["OPENPYPE_EXECUTABLE"] + + executable_filename = os.path.basename(openpype_executable) + if "python" in executable_filename.lower(): + script_path = os.path.join( + os.environ["OPENPYPE_ROOT"], + "{}.py".format(filename) + ) + launch_args = [openpype_executable, script_path] + else: + new_executable = os.path.join( + os.path.dirname(openpype_executable), + filename + ) + executable_path = distutils.spawn.find_executable(new_executable) + if executable_path is None: + return None + launch_args = [executable_path] + + if args: + launch_args.extend(args) + + return launch_args