UI: Added process executor. Display vm status correctly in list. | CLI: Added get_qemu_version(), fixed virtio audio bug.
This commit is contained in:
@@ -1,14 +1,18 @@
|
||||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
import gi
|
||||
from clan_cli import vms
|
||||
|
||||
gi.require_version("Gtk", "3.0")
|
||||
|
||||
from clan_cli.clan_uri import ClanURI
|
||||
from gi.repository import Gio, Gtk
|
||||
|
||||
from .constants import constants
|
||||
from .executor import ProcessManager, spawn
|
||||
from .interfaces import Callbacks, InitialJoinValues
|
||||
from .windows.join import JoinWindow
|
||||
from .windows.overview import OverviewWindow
|
||||
@@ -33,8 +37,15 @@ class Application(Gtk.Application):
|
||||
)
|
||||
self.init_style()
|
||||
self.windows = windows
|
||||
self.proc_manager = ProcessManager()
|
||||
initial = windows.__dict__[config.initial_window]
|
||||
self.cbs = Callbacks(show_list=self.show_list, show_join=self.show_join)
|
||||
self.cbs = Callbacks(
|
||||
show_list=self.show_list,
|
||||
show_join=self.show_join,
|
||||
spawn_vm=self.spawn_vm,
|
||||
stop_vm=self.stop_vm,
|
||||
running_vms=self.running_vms,
|
||||
)
|
||||
if issubclass(initial, JoinWindow):
|
||||
# see JoinWindow constructor
|
||||
self.window = initial(
|
||||
@@ -46,6 +57,37 @@ class Application(Gtk.Application):
|
||||
# see OverviewWindow constructor
|
||||
self.window = initial(cbs=self.cbs)
|
||||
|
||||
# Connect to the shutdown signal
|
||||
self.connect("shutdown", self.on_shutdown)
|
||||
|
||||
def on_shutdown(self, app: Gtk.Application) -> None:
|
||||
print("Shutting down")
|
||||
self.proc_manager.kill_all()
|
||||
|
||||
def spawn_vm(self, url: str, attr: str) -> None:
|
||||
print(f"spawn_vm {url}")
|
||||
|
||||
# TODO: We should use VMConfig from the history file
|
||||
vm = vms.run.inspect_vm(flake_url=url, flake_attr=attr)
|
||||
log_path = Path(".")
|
||||
|
||||
# TODO: We only use the url as the ident. This is not unique as the flake_attr is missing.
|
||||
# when we migrate everything to use the ClanURI class we can use the full url as the ident
|
||||
self.proc_manager.spawn(
|
||||
ident=url,
|
||||
wait_stdin_con=False,
|
||||
log_path=log_path,
|
||||
func=vms.run.run_vm,
|
||||
vm=vm,
|
||||
)
|
||||
|
||||
def stop_vm(self, url: str, attr: str) -> None:
|
||||
print(f"stop_vm {url}")
|
||||
self.proc_manager.kill(url)
|
||||
|
||||
def running_vms(self) -> list[str]:
|
||||
return list(self.proc_manager.procs.keys())
|
||||
|
||||
def show_list(self) -> None:
|
||||
prev = self.window
|
||||
self.window = self.windows.__dict__["overview"](cbs=self.cbs)
|
||||
@@ -125,10 +167,6 @@ def dummy_f(msg: str) -> None:
|
||||
|
||||
|
||||
def show_run_vm(parser: argparse.ArgumentParser) -> None:
|
||||
from pathlib import Path
|
||||
|
||||
from .executor import spawn
|
||||
|
||||
log_path = Path(".").resolve()
|
||||
proc = spawn(wait_stdin_con=True, log_path=log_path, func=dummy_f, msg="Hello")
|
||||
input("Press enter to kill process: ")
|
||||
|
||||
Reference in New Issue
Block a user