All checks were successful
buildbot/nix-build .#checks.x86_64-linux.clan-dep-e2fsprogs Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-bash Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-app-no-breakpoints Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-fakeroot Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-age Build done.
buildbot/nix-build .#checks.aarch64-darwin.nixos-test_install_machine Build done.
buildbot/nix-build .#checks.aarch64-darwin.nixos-iso-installer Build done.
buildbot/nix-build .#checks.x86_64-linux.check-for-breakpoints Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-app-pytest Build done.
buildbot/nix-build .#checks.x86_64-linux.borgbackup Build done.
buildbot/nix-build .#checks.aarch64-darwin.nixos-test-backup Build done.
buildbot/nix-build .#checks.aarch64-darwin.nixos-flash-installer Build done.
buildbot/nix-build .#checks.aarch64-linux.nixos-test_install_machine Build done.
buildbot/nix-build .#checks.aarch64-linux.nixos-test-backup Build done.
buildbot/nix-build .#checks.aarch64-linux.nixos-flash-installer Build done.
buildbot/nix-build .#checks.aarch64-linux.nixos-iso-installer Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-git Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-openssh Build done.
buildbot/nix-build .#checks.x86_64-linux."clan-dep-python3.11-mypy" Build done.
buildbot/nix-build .#checks.x86_64-linux."clan-dep-python3.11-qemu" Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-rsync Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-sops Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-sshpass Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-zbar Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-pytest-without-core Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-webview-ui Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-pytest-with-core Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-clan-cli Build done.
buildbot/nix-build .#checks.x86_64-linux.deltachat Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-default Build done.
buildbot/nix-build .#checks.x86_64-linux.nixos-test_install_machine Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-tor Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-clan-app Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-nix Build done.
buildbot/nix-build .#checks.x86_64-linux.lib-jsonschema-example-valid Build done.
buildbot/nix-build .#checks.x86_64-linux.container Build done.
buildbot/nix-build .#checks.x86_64-linux.package-clan-app Build done.
buildbot/nix-build .#checks.x86_64-linux.package-clan-cli Build done.
buildbot/nix-build .#checks.x86_64-linux.package-clan-cli-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.package-clan-ts-api Build done.
buildbot/nix-build .#checks.x86_64-linux.package-default Build done.
buildbot/nix-build .#checks.x86_64-linux.matrix-synapse Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-install-test-ubuntu-22-04 Build done.
buildbot/nix-build .#checks.x86_64-linux.test-backups Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-installer-apk Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-installer-deb Build done.
buildbot/nix-build .#checks.x86_64-linux.module-schema Build done.
buildbot/nix-build .#checks.x86_64-linux.package-editor Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-installer-archlinux Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-installer-rpm Build done.
buildbot/nix-build .#checks.x86_64-linux.package-impure-checks Build done.
buildbot/nix-build .#checks.x86_64-linux.nixos-test-backup Build done.
buildbot/nix-build .#checks.x86_64-linux.lib-jsonschema-nix-unit-tests Build done.
buildbot/nix-build .#checks.x86_64-linux.package-deploy-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.package-moonlight-sunshine-accept Build done.
buildbot/nix-build .#checks.x86_64-linux.package-pending-reviews Build done.
buildbot/nix-build .#checks.x86_64-linux.package-tea-create-pr Build done.
buildbot/nix-build .#checks.x86_64-linux.package-webview-ui Build done.
buildbot/nix-build .#checks.x86_64-linux.package-zerotier-members Build done.
buildbot/nix-build .#checks.x86_64-linux.package-zerotierone Build done.
buildbot/nix-build .#checks.x86_64-linux.package-zt-tcp-relay Build done.
buildbot/nix-build .#checks.x86_64-linux.package-module-schema Build done.
buildbot/nix-build .#checks.x86_64-linux.nixos-iso-installer Build done.
buildbot/nix-build .#checks.x86_64-linux.nixos-flash-installer Build done.
buildbot/nix-build .#checks.x86_64-linux.secrets Build done.
buildbot/nix-build .#checks.x86_64-linux.treefmt Build done.
buildbot/nix-build .#checks.x86_64-linux.package-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.renderClanOptions Build done.
buildbot/nix-build .#checks.x86_64-linux.package-function-schema Build done.
buildbot/nix-build .#checks.x86_64-linux.package-merge-after-ci Build done.
buildbot/nix-build .#checks.x86_64-linux.package-module-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.wayland-proxy-virtwl Build done.
buildbot/nix-build .#checks.x86_64-linux.zt-tcp-relay Build done.
buildbot/nix-build .#checks.x86_64-linux.package-iso-installer Build done.
buildbot/nix-build .#checks.x86_64-linux.syncthing Build done.
checks / checks-impure (pull_request) Successful in 2m19s
buildbot/nix-build .#checks.x86_64-linux.flash Build done.
buildbot/nix-build .#checks.x86_64-linux.test-installation Build done.
buildbot/nix-eval Build done.
182 lines
5.8 KiB
Python
182 lines
5.8 KiB
Python
import logging
|
|
from collections.abc import Callable
|
|
from pathlib import Path
|
|
from typing import Any, ClassVar
|
|
|
|
import gi
|
|
from clan_cli.clan_uri import ClanURI
|
|
from clan_cli.history.add import HistoryEntry
|
|
|
|
from clan_app import assets
|
|
from clan_app.components.gkvstore import GKVStore
|
|
from clan_app.components.vmobj import VMObject
|
|
from clan_app.singletons.use_views import ViewStack
|
|
from clan_app.views.logs import Logs
|
|
|
|
gi.require_version("GObject", "2.0")
|
|
gi.require_version("Gtk", "4.0")
|
|
from gi.repository import Gio, GLib, GObject
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
class VMStore(GKVStore):
|
|
def __init__(self) -> None:
|
|
super().__init__(VMObject, lambda vm: vm.data.flake.flake_attr)
|
|
|
|
|
|
class Emitter(GObject.GObject):
|
|
__gsignals__: ClassVar = {
|
|
"is_ready": (GObject.SignalFlags.RUN_FIRST, None, []),
|
|
}
|
|
|
|
|
|
class ClanStore:
|
|
_instance: "None | ClanStore" = None
|
|
_clan_store: GKVStore[str, VMStore]
|
|
|
|
_emitter: Emitter
|
|
|
|
# set the vm that is outputting logs
|
|
# build logs are automatically streamed to the logs-view
|
|
_logging_vm: VMObject | None = None
|
|
|
|
# Make sure the VMS class is used as a singleton
|
|
def __init__(self) -> None:
|
|
raise RuntimeError("Call use() instead")
|
|
|
|
@classmethod
|
|
def use(cls: Any) -> "ClanStore":
|
|
if cls._instance is None:
|
|
cls._instance = cls.__new__(cls)
|
|
cls._clan_store = GKVStore(
|
|
VMStore, lambda store: store.first().data.flake.flake_url
|
|
)
|
|
cls._emitter = Emitter()
|
|
|
|
return cls._instance
|
|
|
|
def emit(self, signal: str) -> None:
|
|
self._emitter.emit(signal)
|
|
|
|
def connect(self, signal: str, cb: Callable[(...), Any]) -> None:
|
|
self._emitter.connect(signal, cb)
|
|
|
|
def set_logging_vm(self, ident: str) -> VMObject | None:
|
|
vm = self.get_vm(ClanURI(f"clan://{ident}"))
|
|
if vm is not None:
|
|
self._logging_vm = vm
|
|
|
|
return self._logging_vm
|
|
|
|
def register_on_deep_change(
|
|
self, callback: Callable[[GKVStore, int, int, int], None]
|
|
) -> None:
|
|
"""
|
|
Register a callback that is called when a clan_store or one of the included VMStores changes
|
|
"""
|
|
|
|
def on_vmstore_change(
|
|
store: VMStore, position: int, removed: int, added: int
|
|
) -> None:
|
|
callback(store, position, removed, added)
|
|
|
|
def on_clanstore_change(
|
|
store: "GKVStore", position: int, removed: int, added: int
|
|
) -> None:
|
|
if added > 0:
|
|
store.values()[position].register_on_change(on_vmstore_change)
|
|
callback(store, position, removed, added)
|
|
|
|
self.clan_store.register_on_change(on_clanstore_change)
|
|
|
|
@property
|
|
def clan_store(self) -> GKVStore[str, VMStore]:
|
|
return self._clan_store
|
|
|
|
def create_vm_task(self, vm: HistoryEntry) -> bool:
|
|
self.push_history_entry(vm)
|
|
return GLib.SOURCE_REMOVE
|
|
|
|
def push_history_entry(self, entry: HistoryEntry) -> None:
|
|
# TODO: We shouldn't do this here but in the list view
|
|
if entry.flake.icon is None:
|
|
icon: Path = assets.loc / "placeholder.jpeg"
|
|
else:
|
|
icon = Path(entry.flake.icon)
|
|
|
|
def log_details(gfile: Gio.File) -> None:
|
|
self.log_details(vm, gfile)
|
|
|
|
vm = VMObject(icon=icon, data=entry, build_log_cb=log_details)
|
|
self.push(vm)
|
|
|
|
def log_details(self, vm: VMObject, gfile: Gio.File) -> None:
|
|
views = ViewStack.use().view
|
|
logs_view: Logs = views.get_child_by_name("logs") # type: ignore
|
|
|
|
def file_read_callback(
|
|
source_object: Gio.File, result: Gio.AsyncResult, _user_data: Any
|
|
) -> None:
|
|
try:
|
|
# Finish the asynchronous read operation
|
|
res = source_object.load_contents_finish(result)
|
|
_success, contents, _etag_out = res
|
|
|
|
# Convert the byte array to a string and print it
|
|
logs_view.set_message(contents.decode("utf-8"))
|
|
except Exception as e:
|
|
print(f"Error reading file: {e}")
|
|
|
|
# only one vm can output logs at a time
|
|
if vm == self._logging_vm:
|
|
gfile.load_contents_async(None, file_read_callback, None)
|
|
|
|
# we cannot check this type, python is not smart enough
|
|
|
|
def push(self, vm: VMObject) -> None:
|
|
url = str(vm.data.flake.flake_url)
|
|
|
|
# Only write to the store if the Clan is not already in it
|
|
# Every write to the KVStore rerenders bound widgets to the clan_store
|
|
if url not in self.clan_store:
|
|
log.debug(f"Creating new VMStore for {url}")
|
|
vm_store = VMStore()
|
|
vm_store.append(vm)
|
|
self.clan_store[url] = vm_store
|
|
else:
|
|
vm_store = self.clan_store[url]
|
|
machine = vm.data.flake.flake_attr
|
|
old_vm = vm_store.get(machine)
|
|
|
|
if old_vm:
|
|
log.info(
|
|
f"VM {vm.data.flake.flake_attr} already exists in store. Updating data field."
|
|
)
|
|
old_vm.update(vm.data)
|
|
else:
|
|
log.debug(f"Appending VM {vm.data.flake.flake_attr} to store")
|
|
vm_store.append(vm)
|
|
|
|
def remove(self, vm: VMObject) -> None:
|
|
del self.clan_store[str(vm.data.flake.flake_url)][vm.data.flake.flake_attr]
|
|
|
|
def get_vm(self, uri: ClanURI) -> None | VMObject:
|
|
vm_store = self.clan_store.get(str(uri.flake_id))
|
|
if vm_store is None:
|
|
return None
|
|
machine = vm_store.get(uri.machine.name, None)
|
|
return machine
|
|
|
|
def get_running_vms(self) -> list[VMObject]:
|
|
return [
|
|
vm
|
|
for clan in self.clan_store.values()
|
|
for vm in clan.values()
|
|
if vm.is_running()
|
|
]
|
|
|
|
def kill_all(self) -> None:
|
|
for vm in self.get_running_vms():
|
|
vm.kill()
|