Added new type FlakeName

This commit is contained in:
Qubasa
2023-10-14 15:17:58 +02:00
parent f976121fa6
commit ecdd4949b7
17 changed files with 98 additions and 72 deletions

View File

@@ -5,12 +5,13 @@ from typing import Dict
from ..async_cmd import CmdOut, run, runforcli
from ..dirs import specific_flake_dir, specific_machine_dir
from ..errors import ClanError
from ..flakes.types import FlakeName
from ..nix import nix_shell
log = logging.getLogger(__name__)
async def create_machine(flake_name: str, machine_name: str) -> Dict[str, CmdOut]:
async def create_machine(flake_name: FlakeName, machine_name: str) -> Dict[str, CmdOut]:
folder = specific_machine_dir(flake_name, machine_name)
folder.mkdir(parents=True, exist_ok=True)

View File

@@ -1,9 +1,10 @@
from ..dirs import specific_machine_dir
from ..flakes.types import FlakeName
def machine_has_fact(flake_name: str, machine: str, fact: str) -> bool:
def machine_has_fact(flake_name: FlakeName, machine: str, fact: str) -> bool:
return (specific_machine_dir(flake_name, machine) / "facts" / fact).exists()
def machine_get_fact(flake_name: str, machine: str, fact: str) -> str:
def machine_get_fact(flake_name: FlakeName, machine: str, fact: str) -> str:
return (specific_machine_dir(flake_name, machine) / "facts" / fact).read_text()

View File

@@ -3,12 +3,13 @@ import logging
import os
from ..dirs import machines_dir
from ..flakes.types import FlakeName
from .types import validate_hostname
log = logging.getLogger(__name__)
def list_machines(flake_name: str) -> list[str]:
def list_machines(flake_name: FlakeName) -> list[str]:
path = machines_dir(flake_name)
log.debug(f"Listing machines in {path}")
if not path.exists():