Merge branch 'develop' into enhancement/add-username-to-tray-info

This commit is contained in:
Jakub Trllo 2024-07-24 17:34:05 +02:00 committed by GitHub
commit b534998d24
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 24 additions and 12 deletions

View file

@ -43,7 +43,8 @@ class AliasedGroup(click.Group):
help="Enable debug") help="Enable debug")
@click.option("--verbose", expose_value=False, @click.option("--verbose", expose_value=False,
help=("Change AYON log level (debug - critical or 0-50)")) help=("Change AYON log level (debug - critical or 0-50)"))
def main_cli(ctx): @click.option("--force", is_flag=True, hidden=True)
def main_cli(ctx, force):
"""AYON is main command serving as entry point to pipeline system. """AYON is main command serving as entry point to pipeline system.
It wraps different commands together. It wraps different commands together.
@ -55,17 +56,24 @@ def main_cli(ctx):
print(ctx.get_help()) print(ctx.get_help())
sys.exit(0) sys.exit(0)
else: else:
ctx.invoke(tray) ctx.forward(tray)
@main_cli.command() @main_cli.command()
def tray(): @click.option(
"--force",
is_flag=True,
help="Force to start tray and close any existing one.")
def tray(force):
"""Launch AYON tray. """Launch AYON tray.
Default action of AYON command is to launch tray widget to control basic Default action of AYON command is to launch tray widget to control basic
aspects of AYON. See documentation for more information. aspects of AYON. See documentation for more information.
""" """
Commands.launch_tray()
from ayon_core.tools.tray import main
main(force)
@main_cli.group(help="Run command line arguments of AYON addons") @main_cli.group(help="Run command line arguments of AYON addons")

View file

@ -13,12 +13,6 @@ class Commands:
Most of its methods are called by :mod:`cli` module. Most of its methods are called by :mod:`cli` module.
""" """
@staticmethod
def launch_tray():
from ayon_core.tools.tray import main
main()
@staticmethod @staticmethod
def publish( def publish(
path: str, path: str,

View file

@ -7,6 +7,7 @@ import subprocess
import csv import csv
import time import time
import signal import signal
import locale
from typing import Optional, Dict, Tuple, Any from typing import Optional, Dict, Tuple, Any
import ayon_api import ayon_api
@ -50,7 +51,8 @@ def _get_server_and_variant(
def _windows_pid_is_running(pid: int) -> bool: def _windows_pid_is_running(pid: int) -> bool:
args = ["tasklist.exe", "/fo", "csv", "/fi", f"PID eq {pid}"] args = ["tasklist.exe", "/fo", "csv", "/fi", f"PID eq {pid}"]
output = subprocess.check_output(args) output = subprocess.check_output(args)
csv_content = csv.DictReader(output.decode("utf-8").splitlines()) encoding = locale.getpreferredencoding()
csv_content = csv.DictReader(output.decode(encoding).splitlines())
# if "PID" not in csv_content.fieldnames: # if "PID" not in csv_content.fieldnames:
# return False # return False
for _ in csv_content: for _ in csv_content:
@ -344,12 +346,20 @@ def is_tray_running(
return state != TrayState.NOT_RUNNING return state != TrayState.NOT_RUNNING
def main(): def main(force=False):
from ayon_core.tools.tray.ui import main from ayon_core.tools.tray.ui import main
Logger.set_process_name("Tray") Logger.set_process_name("Tray")
state = get_tray_state() state = get_tray_state()
if force and state in (TrayState.RUNNING, TrayState.STARTING):
file_info = get_tray_file_info() or {}
pid = file_info.get("pid")
if pid is not None:
_kill_tray_process(pid)
remove_tray_server_url(force=True)
state = TrayState.NOT_RUNNING
if state == TrayState.RUNNING: if state == TrayState.RUNNING:
print("Tray is already running.") print("Tray is already running.")
return return