added helper function to determine if ui executable is used

This commit is contained in:
Jakub Trllo 2024-03-25 16:33:02 +01:00
parent 508d4b559e
commit 562730fa65
6 changed files with 63 additions and 40 deletions

View file

@ -2,7 +2,10 @@ import os
import platform
import subprocess
from ayon_core.lib import get_ayon_launcher_args
from ayon_core.lib import (
get_ayon_launcher_args,
is_using_ui_executable,
)
from ayon_core.lib.applications import (
PreLaunchHook,
LaunchTypes,
@ -27,14 +30,7 @@ def get_launch_kwargs(kwargs):
if platform.system().lower() != "windows":
return kwargs
executable_path = os.environ.get("AYON_EXECUTABLE")
executable_filename = ""
if executable_path:
executable_filename = os.path.basename(executable_path)
is_in_ui_launcher = "ayon_console" not in executable_filename
if is_in_ui_launcher:
if is_using_ui_executable():
kwargs.update({
"creationflags": subprocess.CREATE_NO_WINDOW,
"stdout": subprocess.DEVNULL,

View file

@ -15,15 +15,17 @@ import json
import signal
import time
from uuid import uuid4
from qtpy import QtWidgets, QtCore, QtGui
import collections
from .server import Server
from qtpy import QtWidgets, QtCore, QtGui
from ayon_core.lib import is_using_ui_executable
from ayon_core.tools.stdout_broker.app import StdOutBroker
from ayon_core.tools.utils import host_tools
from ayon_core import style
from .server import Server
# Setup logging.
log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)
@ -326,16 +328,15 @@ def launch_zip_file(filepath):
print("Launching {}".format(scene_path))
# QUESTION Could we use 'run_detached_process' from 'ayon_core.lib'?
kwargs = {}
if platform.system().lower() == "windows":
executable_filename = os.path.basename(
os.getenv("AYON_EXECUTABLE", "")
)
if "ayon_console" not in executable_filename:
kwargs.update({
"creationflags": subprocess.CREATE_NO_WINDOW,
"stdout": subprocess.DEVNULL,
"stderr": subprocess.DEVNULL
})
if (
platform.system().lower() == "windows"
and is_using_ui_executable()
):
kwargs.update({
"creationflags": subprocess.CREATE_NO_WINDOW,
"stdout": subprocess.DEVNULL,
"stderr": subprocess.DEVNULL
})
process = subprocess.Popen(
[ProcessContext.application_path, scene_path],

View file

@ -2,7 +2,10 @@ import os
import platform
import subprocess
from ayon_core.lib import get_ayon_launcher_args
from ayon_core.lib import (
get_ayon_launcher_args,
is_using_ui_executable,
)
from ayon_core.lib.applications import (
PreLaunchHook,
LaunchTypes,
@ -27,14 +30,7 @@ def get_launch_kwargs(kwargs):
if platform.system().lower() != "windows":
return kwargs
executable_path = os.environ.get("AYON_EXECUTABLE")
executable_filename = ""
if executable_path:
executable_filename = os.path.basename(executable_path)
is_gui_executable = "ayon_console" not in executable_filename
if is_gui_executable:
if is_using_ui_executable():
kwargs.update({
"creationflags": subprocess.CREATE_NO_WINDOW,
"stdout": subprocess.DEVNULL,

View file

@ -2,7 +2,10 @@ import os
import platform
import subprocess
from ayon_core.lib import get_ayon_launcher_args
from ayon_core.lib import (
get_ayon_launcher_args,
is_using_ui_executable,
)
from ayon_core.lib.applications import (
PreLaunchHook,
LaunchTypes,
@ -27,14 +30,7 @@ def get_launch_kwargs(kwargs):
if platform.system().lower() != "windows":
return kwargs
executable_path = os.environ.get("AYON_EXECUTABLE")
executable_filename = ""
if executable_path:
executable_filename = os.path.basename(executable_path)
is_gui_executable = "ayon_console" not in executable_filename
if is_gui_executable:
if is_using_ui_executable():
kwargs.update({
"creationflags": subprocess.CREATE_NO_WINDOW,
"stdout": subprocess.DEVNULL,

View file

@ -155,6 +155,7 @@ from .path_tools import (
from .ayon_info import (
is_running_from_build,
is_using_ui_executable,
is_staging_enabled,
is_dev_mode_enabled,
is_in_tests,
@ -275,6 +276,7 @@ __all__ = [
"Logger",
"is_running_from_build",
"is_using_ui_executable",
"is_staging_enabled",
"is_dev_mode_enabled",
"is_in_tests",

View file

@ -10,6 +10,12 @@ from .local_settings import get_local_site_id
def get_ayon_launcher_version():
"""Get AYON launcher version.
Returns:
str: Version string.
"""
version_filepath = os.path.join(os.environ["AYON_ROOT"], "version.py")
if not os.path.exists(version_filepath):
return None
@ -24,8 +30,8 @@ def is_running_from_build():
Returns:
bool: True if running from build.
"""
"""
executable_path = os.environ["AYON_EXECUTABLE"]
executable_filename = os.path.basename(executable_path)
if "python" in executable_filename.lower():
@ -33,6 +39,32 @@ def is_running_from_build():
return True
def is_using_ui_executable():
"""AYON launcher UI windows executable is used.
This function make sense only on Windows platform. For other platforms
always returns False. False is also returned if process is running from
code.
AYON launcher on windows has 2 executable files. First 'ayon_console.exe'
works as 'python.exe' executable, the second 'ayon.exe' works as
'pythonw.exe' executable. The difference is way how stdout/stderr is
handled (especially when calling subprocess).
Returns:
bool: True if UI executable is used.
"""
if (
platform.system().lower() != "windows"
or is_running_from_build()
):
return False
executable_path = os.environ["AYON_EXECUTABLE"]
executable_filename = os.path.basename(executable_path)
return "ayon_console" not in executable_filename
def is_staging_enabled():
return os.getenv("AYON_USE_STAGING") == "1"