From 48367f2638ebb714d7e187ce71f33a97e8cf01c8 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Wed, 5 Jun 2024 13:47:22 +0200 Subject: [PATCH] fix circular import --- client/ayon_core/modules/webserver/__init__.py | 2 ++ .../modules/webserver/host_console_listener.py | 18 +++++++----------- .../ayon_core/modules/webserver/structures.py | 6 ++++++ client/ayon_core/tools/stdout_broker/broker.py | 10 +++++----- 4 files changed, 20 insertions(+), 16 deletions(-) create mode 100644 client/ayon_core/modules/webserver/structures.py diff --git a/client/ayon_core/modules/webserver/__init__.py b/client/ayon_core/modules/webserver/__init__.py index a978b94bc4..32f2c55f65 100644 --- a/client/ayon_core/modules/webserver/__init__.py +++ b/client/ayon_core/modules/webserver/__init__.py @@ -1,4 +1,5 @@ from .version import __version__ +from .structures import HostMsgAction from .webserver_module import ( WebServerAddon ) @@ -7,5 +8,6 @@ from .webserver_module import ( __all__ = ( "__version__", + "HostMsgAction", "WebServerAddon", ) diff --git a/client/ayon_core/modules/webserver/host_console_listener.py b/client/ayon_core/modules/webserver/host_console_listener.py index ed8a32b9f2..2efd768e24 100644 --- a/client/ayon_core/modules/webserver/host_console_listener.py +++ b/client/ayon_core/modules/webserver/host_console_listener.py @@ -9,22 +9,18 @@ from qtpy import QtWidgets from ayon_core.addon import ITrayService from ayon_core.tools.stdout_broker.window import ConsoleDialog +from .structures import HostMsgAction + log = logging.getLogger(__name__) +# Host listener icon type class IconType: IDLE = "idle" RUNNING = "running" FAILED = "failed" -class MsgAction: - CONNECTING = "connecting" - INITIALIZED = "initialized" - ADD = "add" - CLOSE = "close" - - class HostListener: def __init__(self, webserver, module): self._window_per_id = {} @@ -96,22 +92,22 @@ class HostListener: if msg.type == aiohttp.WSMsgType.TEXT: host_name, action, text = self._parse_message(msg) - if action == MsgAction.CONNECTING: + if action == HostMsgAction.CONNECTING: self._action_per_id[host_name] = None # must be sent to main thread, or action wont trigger self.module.execute_in_main_thread( lambda: self._host_is_connecting(host_name, text)) - elif action == MsgAction.CLOSE: + elif action == HostMsgAction.CLOSE: # clean close self._close(host_name) await ws.close() - elif action == MsgAction.INITIALIZED: + elif action == HostMsgAction.INITIALIZED: self.module.execute_in_main_thread( # must be queued as _host_is_connecting might not # be triggered/finished yet lambda: self._set_host_icon(host_name, IconType.RUNNING)) - elif action == MsgAction.ADD: + elif action == HostMsgAction.ADD: self.module.execute_in_main_thread( lambda: self._add_text(host_name, text)) elif msg.type == aiohttp.WSMsgType.ERROR: diff --git a/client/ayon_core/modules/webserver/structures.py b/client/ayon_core/modules/webserver/structures.py new file mode 100644 index 0000000000..a598e3342a --- /dev/null +++ b/client/ayon_core/modules/webserver/structures.py @@ -0,0 +1,6 @@ +# Host listener message actions +class HostMsgAction: + CONNECTING = "connecting" + INITIALIZED = "initialized" + ADD = "add" + CLOSE = "close" diff --git a/client/ayon_core/tools/stdout_broker/broker.py b/client/ayon_core/tools/stdout_broker/broker.py index e31eb0057e..291936008b 100644 --- a/client/ayon_core/tools/stdout_broker/broker.py +++ b/client/ayon_core/tools/stdout_broker/broker.py @@ -8,7 +8,7 @@ from datetime import datetime import websocket from ayon_core.lib import Logger -from ayon_core.modules.webserver.host_console_listener import MsgAction +from ayon_core.modules.webserver import HostMsgAction log = Logger.get_logger(__name__) @@ -65,7 +65,7 @@ class StdOutBroker: payload = { "host": self.host_id, - "action": MsgAction.INITIALIZED, + "action": HostMsgAction.INITIALIZED, "text": "Integration with {}".format( str.capitalize(self.host_name)) } @@ -99,7 +99,7 @@ class StdOutBroker: payload = { "host": self.host_id, - "action": MsgAction.CONNECTING, + "action": HostMsgAction.CONNECTING, "text": "Integration with {}".format( str.capitalize(self.host_name)) } @@ -113,7 +113,7 @@ class StdOutBroker: payload = { "host": self.host_id, - "action": MsgAction.CLOSE, + "action": HostMsgAction.CLOSE, "text": "Integration with {}".format( str.capitalize(self.host_name)) } @@ -157,7 +157,7 @@ class StdOutBroker: if lines: payload = { "host": self.host_id, - "action": MsgAction.ADD, + "action": HostMsgAction.ADD, "text": "\n".join(lines) }