cli machines update: find flake dir automatic if not provided, support flake as path
This commit is contained in:
@@ -2,6 +2,7 @@ import logging
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from .errors import ClanError
|
from .errors import ClanError
|
||||||
from .types import FlakeName
|
from .types import FlakeName
|
||||||
@@ -9,27 +10,27 @@ from .types import FlakeName
|
|||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
# def _get_clan_flake_toplevel() -> Path:
|
def get_clan_flake_toplevel() -> Path:
|
||||||
# return find_toplevel([".clan-flake", ".git", ".hg", ".svn", "flake.nix"])
|
return find_toplevel([".clan-flake", ".git", ".hg", ".svn", "flake.nix"])
|
||||||
|
|
||||||
|
|
||||||
# def find_git_repo_root() -> Optional[Path]:
|
def find_git_repo_root() -> Optional[Path]:
|
||||||
# try:
|
try:
|
||||||
# return find_toplevel([".git"])
|
return find_toplevel([".git"])
|
||||||
# except ClanError:
|
except ClanError:
|
||||||
# return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
# def find_toplevel(top_level_files: list[str]) -> Path:
|
def find_toplevel(top_level_files: list[str]) -> Path:
|
||||||
# """Returns the path to the toplevel of the clan flake"""
|
"""Returns the path to the toplevel of the clan flake"""
|
||||||
# for project_file in top_level_files:
|
for project_file in top_level_files:
|
||||||
# initial_path = Path(os.getcwd())
|
initial_path = Path(os.getcwd())
|
||||||
# path = Path(initial_path)
|
path = Path(initial_path)
|
||||||
# while path.parent != path:
|
while path.parent != path:
|
||||||
# if (path / project_file).exists():
|
if (path / project_file).exists():
|
||||||
# return path
|
return path
|
||||||
# path = path.parent
|
path = path.parent
|
||||||
# raise ClanError("Could not find clan flake toplevel directory")
|
raise ClanError("Could not find clan flake toplevel directory")
|
||||||
|
|
||||||
|
|
||||||
def user_config_dir() -> Path:
|
def user_config_dir() -> Path:
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import os
|
|||||||
import subprocess
|
import subprocess
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from ..dirs import specific_flake_dir
|
from ..dirs import get_clan_flake_toplevel
|
||||||
from ..machines.machines import Machine
|
from ..machines.machines import Machine
|
||||||
from ..nix import nix_build, nix_command, nix_config
|
from ..nix import nix_build, nix_command, nix_config
|
||||||
from ..secrets.generate import generate_secrets
|
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.
|
# FIXME: we want some kind of inventory here.
|
||||||
def update(args: argparse.Namespace) -> None:
|
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:
|
if len(args.machines) == 1 and args.target_host is not None:
|
||||||
machine = Machine(name=args.machines[0], flake_dir=flake_dir)
|
machine = Machine(name=args.machines[0], flake_dir=flake_dir)
|
||||||
machine.deployment_address = args.target_host
|
machine.deployment_address = args.target_host
|
||||||
@@ -148,9 +151,10 @@ def register_update_parser(parser: argparse.ArgumentParser) -> None:
|
|||||||
default=[],
|
default=[],
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"flake",
|
"--flake",
|
||||||
type=str,
|
type=str,
|
||||||
help="name of the flake to update machine for",
|
help="name of the flake to update machine for",
|
||||||
|
default=None,
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--target-host",
|
"--target-host",
|
||||||
|
|||||||
Reference in New Issue
Block a user