From 1eb0daa71191886feab1d70f55d62ae83a924f51 Mon Sep 17 00:00:00 2001 From: mirkobrombin Date: Mon, 1 Jul 2024 13:05:16 +0200 Subject: [PATCH] fix[close #59]: Creating subsystem does not show anything and just frezes --- apx_gui/core/apx_entities.py | 76 ++++++++++++++++++----------- apx_gui/gtk/tab-subsystem.ui | 6 +-- apx_gui/widgets/entry_subsystem.py | 2 +- apx_gui/widgets/tab_subsystem.py | 18 +++---- apx_gui/windows/create_subsystem.py | 35 ++++++------- 5 files changed, 79 insertions(+), 58 deletions(-) diff --git a/apx_gui/core/apx_entities.py b/apx_gui/core/apx_entities.py index a5fba2a..2c0fdbe 100644 --- a/apx_gui/core/apx_entities.py +++ b/apx_gui/core/apx_entities.py @@ -27,7 +27,7 @@ from typing import Any from collections.abc import Callable -from gi.repository import Vte, GLib +from gi.repository import Vte, GLib # type: ignore from time import sleep @@ -51,6 +51,13 @@ def _get_apx_command(self) -> str: else: return self.__apx_bin + def _get_apx_command_as_args(self) -> list[str]: + args: list[str] = [] + if self._is_running_in_container(): + args.append(self.__host_spawn_bin) + args.append("apx") + return args + @property def __apx_bin(self) -> str: """ @@ -136,7 +143,6 @@ def create(self) -> tuple[bool, "Stack"]: ) new_res: tuple[bool, str] = self._run_command(new_command) - list_command: str = f"apx stacks list --json" list_res: tuple[bool, str] = self._run_command(list_command) if not list_res[0]: @@ -181,26 +187,31 @@ def __init__( self.stack: Stack = stack self.status: str = status self.enter_command: list[str] = enter_command + if enter_command == []: + self.enter_command = shlex.split(f"{self._get_apx_command()} {name} enter") self.exported_programs: dict[str, dict[str, str]] = exported_programs or {} def create( self, - _terminal, + terminal: Vte.Terminal, ) -> tuple[bool, "Subsystem"]: - new_command = ( - f"{self._get_apx_command()}", - "subsystems", - "new", - "--name", - f"{self.name}", - "--stack", - f"{self.stack.name}", + new_command = self._get_apx_command_as_args() + new_command.extend( + [ + "subsystems", + "new", + "--name", + f"{self.name}", + "--stack", + f"{self.stack.name}", + ] ) # the following apx command is safe to ignore errors, we´ll check the # subsystem status by getting the list of subsystems - self.run_vte_command(new_command, _terminal, self._Create_Callback) + res: bool = self.run_vte_command(new_command, terminal, self._create_callback) + return res, self - def _create_callback(self,*args): + def _create_callback(self, *args): list_command: str = f"subsystems list --json" list_res: tuple[bool, str] = self._run_apx_command(list_command) if not list_res[0]: @@ -222,23 +233,33 @@ def _create_callback(self,*args): def run_vte_command( self, args, - __terminal, - __callbackfunc, - ) -> tuple[bool, str]: + terminal, + callback_fn, + ) -> bool: """ Run the 'apx' command with the specified arguments. """ - __terminal.connect("child-exited", __callbackfunc) - Term = __terminal.spawn_sync( - Vte.PtyFlags.DEFAULT, - ".", - args, - [], - GLib.SpawnFlags.DO_NOT_REAP_CHILD, - None, - None, - None, - ) + terminal.connect("child-exited", callback_fn) + + res: bool = False + try: + print(f"Running command: {args}") + res = terminal.spawn_sync( + Vte.PtyFlags.DEFAULT, + ".", + args, + [], + GLib.SpawnFlags.DO_NOT_REAP_CHILD, + None, + None, + None, + ) + print(f"Spawn result: {res}") + except Exception as e: + print(f"Exception: {e}") + return False + + return res @property def running(self) -> bool: @@ -372,4 +393,3 @@ def update( f"--update '{cmd_update}' --upgrade '{cmd_upgrade}'" ) return self._run_apx_command(command) - diff --git a/apx_gui/gtk/tab-subsystem.ui b/apx_gui/gtk/tab-subsystem.ui index 3aea853..425e4b7 100644 --- a/apx_gui/gtk/tab-subsystem.ui +++ b/apx_gui/gtk/tab-subsystem.ui @@ -58,10 +58,10 @@ Subsystem actions - - btn_startstop + + btn_start_stop - + center