multi join via cli #795
@ -7,6 +7,7 @@ import logging
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from clan_cli.flakes.inspect import FlakeConfig, inspect_flake
|
from clan_cli.flakes.inspect import FlakeConfig, inspect_flake
|
||||||
|
from clan_cli.machines.list import list_machines
|
||||||
|
|
||||||
from ..clan_uri import ClanURI
|
from ..clan_uri import ClanURI
|
||||||
from ..dirs import user_history_file
|
from ..dirs import user_history_file
|
||||||
@ -66,8 +67,8 @@ def list_history() -> list[HistoryEntry]:
|
|||||||
return logs
|
return logs
|
||||||
|
|
||||||
|
|
||||||
def new_history_entry(uri: ClanURI) -> HistoryEntry:
|
def new_history_entry(url: str, machine: str) -> HistoryEntry:
|
||||||
flake = inspect_flake(uri.get_internal(), uri.params.flake_attr)
|
flake = inspect_flake(url, machine)
|
||||||
flake.flake_url = str(flake.flake_url)
|
flake.flake_url = str(flake.flake_url)
|
||||||
return HistoryEntry(
|
return HistoryEntry(
|
||||||
flake=flake,
|
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)
|
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
|
found = False
|
||||||
uri_path = uri.get_internal()
|
|
||||||
uri_machine = uri.params.flake_attr
|
|
||||||
|
|
||||||
for entry in logs:
|
for entry in logs:
|
||||||
if (
|
if (
|
||||||
@ -91,16 +104,12 @@ def add_history(uri: ClanURI) -> list[HistoryEntry]:
|
|||||||
entry.last_used = datetime.datetime.now().isoformat()
|
entry.last_used = datetime.datetime.now().isoformat()
|
||||||
|
|
||||||
if not found:
|
if not found:
|
||||||
history = new_history_entry(uri)
|
history = new_history_entry(uri_path, uri_machine)
|
||||||
logs.append(history)
|
logs.append(history)
|
||||||
|
|
||||||
write_history_file(logs)
|
|
||||||
|
|
||||||
return logs
|
|
||||||
|
|
||||||
|
|
||||||
def add_history_command(args: argparse.Namespace) -> None:
|
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
|
# takes a (sub)parser and configures it
|
||||||
@ -108,4 +117,7 @@ def register_add_parser(parser: argparse.ArgumentParser) -> None:
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"uri", type=ClanURI.from_str, help="Path to the flake", default="."
|
"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)
|
parser.set_defaults(func=add_history_command)
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
# !/usr/bin/env python3
|
# !/usr/bin/env python3
|
||||||
import argparse
|
import argparse
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
from clan_cli.flakes.inspect import inspect_flake
|
||||||
|
|
||||||
from ..clan_uri import ClanParameters, ClanURI
|
from ..clan_uri import ClanParameters, ClanURI
|
||||||
from ..errors import ClanCmdError
|
from ..errors import ClanCmdError
|
||||||
from ..locked_open import write_history_file
|
from ..locked_open import write_history_file
|
||||||
from ..nix import nix_metadata
|
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]:
|
def update_history() -> list[HistoryEntry]:
|
||||||
@ -27,7 +30,11 @@ def update_history() -> list[HistoryEntry]:
|
|||||||
url=str(entry.flake.flake_url),
|
url=str(entry.flake.flake_url),
|
||||||
params=ClanParameters(entry.flake.flake_attr),
|
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)
|
write_history_file(logs)
|
||||||
return logs
|
return logs
|
||||||
|
@ -7,7 +7,7 @@ from clan_vm_manager.views.list import ClanList
|
|||||||
|
|
||||||
gi.require_version("Adw", "1")
|
gi.require_version("Adw", "1")
|
||||||
|
|
||||||
from gi.repository import Adw
|
from gi.repository import Adw, Gtk
|
||||||
|
|
||||||
|
|
||||||
class MainWindow(Adw.ApplicationWindow):
|
class MainWindow(Adw.ApplicationWindow):
|
||||||
@ -26,7 +26,12 @@ class MainWindow(Adw.ApplicationWindow):
|
|||||||
stack_view = Views.use().view
|
stack_view = Views.use().view
|
||||||
Views.use().set_main_window(self)
|
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.add_named(Details(), "details")
|
||||||
|
|
||||||
stack_view.set_visible_child_name(config.initial_view)
|
stack_view.set_visible_child_name(config.initial_view)
|
||||||
|
Loading…
Reference in New Issue
Block a user