Merge pull request 'cli machines update: find flake dir automatic if not provided, support flake as path' (#441) from lassulus-HEAD into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/441
This commit is contained in:
@@ -2,6 +2,7 @@ import logging
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
from .errors import ClanError
|
||||
from .types import FlakeName
|
||||
@@ -9,27 +10,27 @@ from .types import FlakeName
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# def _get_clan_flake_toplevel() -> Path:
|
||||
# return find_toplevel([".clan-flake", ".git", ".hg", ".svn", "flake.nix"])
|
||||
def get_clan_flake_toplevel() -> Path:
|
||||
return find_toplevel([".clan-flake", ".git", ".hg", ".svn", "flake.nix"])
|
||||
|
||||
|
||||
# def find_git_repo_root() -> Optional[Path]:
|
||||
# try:
|
||||
# return find_toplevel([".git"])
|
||||
# except ClanError:
|
||||
# return None
|
||||
def find_git_repo_root() -> Optional[Path]:
|
||||
try:
|
||||
return find_toplevel([".git"])
|
||||
except ClanError:
|
||||
return None
|
||||
|
||||
|
||||
# def find_toplevel(top_level_files: list[str]) -> Path:
|
||||
# """Returns the path to the toplevel of the clan flake"""
|
||||
# for project_file in top_level_files:
|
||||
# initial_path = Path(os.getcwd())
|
||||
# path = Path(initial_path)
|
||||
# while path.parent != path:
|
||||
# if (path / project_file).exists():
|
||||
# return path
|
||||
# path = path.parent
|
||||
# raise ClanError("Could not find clan flake toplevel directory")
|
||||
def find_toplevel(top_level_files: list[str]) -> Path:
|
||||
"""Returns the path to the toplevel of the clan flake"""
|
||||
for project_file in top_level_files:
|
||||
initial_path = Path(os.getcwd())
|
||||
path = Path(initial_path)
|
||||
while path.parent != path:
|
||||
if (path / project_file).exists():
|
||||
return path
|
||||
path = path.parent
|
||||
raise ClanError("Could not find clan flake toplevel directory")
|
||||
|
||||
|
||||
def user_config_dir() -> Path:
|
||||
|
||||
@@ -13,7 +13,7 @@ from ..nix import nix_command, nix_shell
|
||||
|
||||
DEFAULT_URL: AnyUrl = parse_obj_as(
|
||||
AnyUrl,
|
||||
"git+https://git.clan.lol/clan/clan-core?ref=Qubasa-main#new-clan", # TODO: Change me back to main branch
|
||||
"git+https://git.clan.lol/clan/clan-core?new-clan",
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import os
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
from ..dirs import specific_flake_dir
|
||||
from ..dirs import get_clan_flake_toplevel
|
||||
from ..machines.machines import Machine
|
||||
from ..nix import nix_build, nix_command, nix_config
|
||||
from ..secrets.generate import generate_secrets
|
||||
@@ -116,7 +116,10 @@ def get_selected_machines(machine_names: list[str], flake_dir: Path) -> HostGrou
|
||||
|
||||
# FIXME: we want some kind of inventory here.
|
||||
def update(args: argparse.Namespace) -> None:
|
||||
flake_dir = specific_flake_dir(args.flake)
|
||||
if args.flake is None:
|
||||
flake_dir = get_clan_flake_toplevel()
|
||||
else:
|
||||
flake_dir = args.flake
|
||||
if len(args.machines) == 1 and args.target_host is not None:
|
||||
machine = Machine(name=args.machines[0], flake_dir=flake_dir)
|
||||
machine.deployment_address = args.target_host
|
||||
@@ -148,9 +151,10 @@ def register_update_parser(parser: argparse.ArgumentParser) -> None:
|
||||
default=[],
|
||||
)
|
||||
parser.add_argument(
|
||||
"flake",
|
||||
"--flake",
|
||||
type=str,
|
||||
help="name of the flake to update machine for",
|
||||
default=None,
|
||||
)
|
||||
parser.add_argument(
|
||||
"--target-host",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
description = "<Put your description here>";
|
||||
|
||||
inputs.clan-core.url = "git+https://git.clan.lol/clan/clan-core?ref=Qubasa-main";
|
||||
inputs.clan-core.url = "git+https://git.clan.lol/clan/clan-core";
|
||||
|
||||
outputs = { self, clan-core, ... }:
|
||||
let
|
||||
|
||||
Reference in New Issue
Block a user