From e57169cb29d5f0033b3068625686b8c3cb2d63ef Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Fri, 2 Feb 2024 10:56:08 +0700 Subject: [PATCH] multi join via cli --- pkgs/clan-cli/clan_cli/history/add.py | 36 ++++++++++++------- pkgs/clan-cli/clan_cli/history/update.py | 11 ++++-- .../clan_vm_manager/windows/main_window.py | 9 +++-- 3 files changed, 40 insertions(+), 16 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/history/add.py b/pkgs/clan-cli/clan_cli/history/add.py index 3871f962..3f126b2e 100644 --- a/pkgs/clan-cli/clan_cli/history/add.py +++ b/pkgs/clan-cli/clan_cli/history/add.py @@ -7,6 +7,7 @@ import logging from typing import Any from clan_cli.flakes.inspect import FlakeConfig, inspect_flake +from clan_cli.machines.list import list_machines from ..clan_uri import ClanURI from ..dirs import user_history_file @@ -66,8 +67,8 @@ def list_history() -> list[HistoryEntry]: return logs -def new_history_entry(uri: ClanURI) -> HistoryEntry: - flake = inspect_flake(uri.get_internal(), uri.params.flake_attr) +def new_history_entry(url: str, machine: str) -> HistoryEntry: + flake = inspect_flake(url, machine) flake.flake_url = str(flake.flake_url) return HistoryEntry( flake=flake, @@ -75,12 +76,24 @@ def new_history_entry(uri: ClanURI) -> HistoryEntry: ) -def add_history(uri: ClanURI) -> list[HistoryEntry]: +def add_history(uri: ClanURI, *, all_machines: bool) -> list[HistoryEntry]: user_history_file().parent.mkdir(parents=True, exist_ok=True) - logs = list_history() + history = list_history() + if not all_machines: + add_maschine_to_history(uri.get_internal(), uri.params.flake_attr, history) + + if all_machines: + for machine in list_machines(uri.get_internal()): + add_maschine_to_history(uri.get_internal(), machine, history) + + write_history_file(history) + return history + + +def add_maschine_to_history( + uri_path: str, uri_machine: str, logs: list[HistoryEntry] +) -> None: found = False - uri_path = uri.get_internal() - uri_machine = uri.params.flake_attr for entry in logs: if ( @@ -91,16 +104,12 @@ def add_history(uri: ClanURI) -> list[HistoryEntry]: entry.last_used = datetime.datetime.now().isoformat() if not found: - history = new_history_entry(uri) + history = new_history_entry(uri_path, uri_machine) logs.append(history) - write_history_file(logs) - - return logs - def add_history_command(args: argparse.Namespace) -> None: - add_history(args.uri) + add_history(args.uri, all_machines=args.all) # takes a (sub)parser and configures it @@ -108,4 +117,7 @@ def register_add_parser(parser: argparse.ArgumentParser) -> None: parser.add_argument( "uri", type=ClanURI.from_str, help="Path to the flake", default="." ) + parser.add_argument( + "--all", help="Add all machines", default=False, action="store_true" + ) parser.set_defaults(func=add_history_command) diff --git a/pkgs/clan-cli/clan_cli/history/update.py b/pkgs/clan-cli/clan_cli/history/update.py index eb528024..9b176dea 100644 --- a/pkgs/clan-cli/clan_cli/history/update.py +++ b/pkgs/clan-cli/clan_cli/history/update.py @@ -1,11 +1,14 @@ # !/usr/bin/env python3 import argparse +import datetime + +from clan_cli.flakes.inspect import inspect_flake from ..clan_uri import ClanParameters, ClanURI from ..errors import ClanCmdError from ..locked_open import write_history_file from ..nix import nix_metadata -from .add import HistoryEntry, list_history, new_history_entry +from .add import HistoryEntry, list_history def update_history() -> list[HistoryEntry]: @@ -27,7 +30,11 @@ def update_history() -> list[HistoryEntry]: url=str(entry.flake.flake_url), params=ClanParameters(entry.flake.flake_attr), ) - entry = new_history_entry(uri) + flake = inspect_flake(uri.get_internal(), uri.params.flake_attr) + flake.flake_url = str(flake.flake_url) + entry = HistoryEntry( + flake=flake, last_used=datetime.datetime.now().isoformat() + ) write_history_file(logs) return logs diff --git a/pkgs/clan-vm-manager/clan_vm_manager/windows/main_window.py b/pkgs/clan-vm-manager/clan_vm_manager/windows/main_window.py index 52b85941..b24d41ac 100644 --- a/pkgs/clan-vm-manager/clan_vm_manager/windows/main_window.py +++ b/pkgs/clan-vm-manager/clan_vm_manager/windows/main_window.py @@ -7,7 +7,7 @@ from clan_vm_manager.views.list import ClanList gi.require_version("Adw", "1") -from gi.repository import Adw +from gi.repository import Adw, Gtk class MainWindow(Adw.ApplicationWindow): @@ -26,7 +26,12 @@ class MainWindow(Adw.ApplicationWindow): stack_view = Views.use().view Views.use().set_main_window(self) - stack_view.add_named(ClanList(), "list") + scroll = Gtk.ScrolledWindow() + scroll.set_propagate_natural_height(True) + scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) + scroll.set_child(ClanList()) + + stack_view.add_named(scroll, "list") stack_view.add_named(Details(), "details") stack_view.set_visible_child_name(config.initial_view)