UI: Added signal handling for stopped and started vm.

This commit is contained in:
Qubasa
2024-01-19 18:52:51 +01:00
parent 0c167d1e51
commit d956dbeb77
7 changed files with 111 additions and 48 deletions

View File

@@ -38,11 +38,12 @@ FORMATTER = {
class CustomFormatter(logging.Formatter):
def __init__(self, log_locations: bool) -> None:
super().__init__()
self.log_locations = log_locations
def format(self, record: logging.LogRecord) -> str:
if record.levelno == logging.DEBUG:
return FORMATTER[record.levelno](record, True).format(record)
else:
return FORMATTER[record.levelno](record, False).format(record)
return FORMATTER[record.levelno](record, self.log_locations).format(record)
class ThreadFormatter(logging.Formatter):
@@ -75,7 +76,7 @@ def setup_logging(level: Any) -> None:
# Create and add your custom handler
default_handler.setLevel(level)
default_handler.setFormatter(CustomFormatter())
default_handler.setFormatter(CustomFormatter(level == logging.DEBUG))
main_logger.addHandler(default_handler)
# Set logging level for other modules used by this module

View File

@@ -1,11 +1,10 @@
import os
import shutil
from math import floor
from pathlib import Path
from typing import NamedTuple
def get_term_filler(name: str) -> int:
width, height = os.get_terminal_size()
width, height = shutil.get_terminal_size()
filler = floor((width - len(name)) / 2)
return filler - 1
@@ -16,16 +15,25 @@ def text_heading(heading: str) -> str:
return f"{'=' * filler} {heading} {'=' * filler}"
class CmdOut(NamedTuple):
stdout: str
stderr: str
cwd: Path
command: str
returncode: int
msg: str | None = None
class CmdOut:
def __init__(
self,
stdout: str,
stderr: str,
cwd: Path,
command: str,
returncode: int,
msg: str | None,
) -> None:
super().__init__()
self.stdout = stdout
self.stderr = stderr
self.cwd = cwd
self.command = command
self.returncode = returncode
self.msg = msg
def __str__(self) -> str:
return f"""
self.error_str = f"""
{text_heading(heading="Command")}
{self.command}
{text_heading(heading="Stderr")}
@@ -36,7 +44,10 @@ class CmdOut(NamedTuple):
Message: {self.msg}
Working Directory: '{self.cwd}'
Return Code: {self.returncode}
"""
"""
def __str__(self) -> str:
return self.error_str
class ClanError(Exception):

View File

@@ -72,7 +72,7 @@ def qemu_command(
kernel_cmdline.append("console=tty0")
# fmt: off
command = [
"qemu-kvm",
"qemu-kvms",
"-name", vm.flake_attr,
"-m", f'{nixos_config["memorySize"]}M',
"-smp", str(nixos_config["cores"]),