Bash scripts were untestable and duplicated device/LUKS/mount logic; the lim/ package centralizes it behind one subprocess wrapper and a YAML image catalog (single point of truth). BREAKING CHANGE: scripts/*.sh removed. Use `lim --type <cmd>`; new types mount/umount/single-boot/raid1-boot/lock/unlock/import/export replace direct script calls. --extra is deprecated and ignored. - distributions.yml + lim/catalog.py hold the image catalog (PyYAML) - pytest suite: 102 tests with mocked subprocess (tests/unit) and a 250-line max file-length guard (tests/lint) - ruff strict (select ALL), GitHub Actions CI, Dependabot; Travis gone - Makefile: install (symlink ~/.local/bin/lim) and test targets - fixes over bash: SUDO_USER-aware chown, mmcblk/nvme partition paths, sha512 checksum support, whole-pipeline failure detection, blkid UUID fallback for pre-mounted images, conditional fstab seeding for PARTUUID/LABEL images, clean errors for missing binaries
63 lines
1.3 KiB
Python
63 lines
1.3 KiB
Python
"""Colored console messages and interactive prompts."""
|
|
|
|
import sys
|
|
|
|
_USE_COLOR = sys.stdout.isatty()
|
|
|
|
|
|
def _color(code: str) -> str:
|
|
return f"\033[{code}m" if _USE_COLOR else ""
|
|
|
|
|
|
COLOR_RED = _color("31")
|
|
COLOR_GREEN = _color("32")
|
|
COLOR_YELLOW = _color("33")
|
|
COLOR_BLUE = _color("34")
|
|
COLOR_MAGENTA = _color("35")
|
|
COLOR_CYAN = _color("36")
|
|
COLOR_WHITE = _color("37")
|
|
COLOR_RESET = _color("0")
|
|
|
|
|
|
def message(color: str, tag: str, text: str) -> None:
|
|
print(f"{color}[{tag}]:{COLOR_RESET} {text}")
|
|
|
|
|
|
def question(text: str) -> None:
|
|
message(COLOR_MAGENTA, "QUESTION", text)
|
|
|
|
|
|
def info(text: str) -> None:
|
|
message(COLOR_BLUE, "INFO", text)
|
|
|
|
|
|
def warning(text: str) -> None:
|
|
message(COLOR_YELLOW, "WARNING", text)
|
|
|
|
|
|
def success(text: str) -> None:
|
|
message(COLOR_GREEN, "SUCCESS", text)
|
|
|
|
|
|
def error(text: str) -> None:
|
|
message(COLOR_RED, "ERROR", text)
|
|
|
|
|
|
def ask(prompt: str) -> str:
|
|
question(prompt)
|
|
return input().strip()
|
|
|
|
|
|
def confirm(prompt: str) -> bool:
|
|
return ask(f"{prompt}(y/N)") == "y"
|
|
|
|
|
|
def header() -> None:
|
|
print(
|
|
f"\n{COLOR_YELLOW}The\n"
|
|
"LINUX IMAGE MANAGER\n"
|
|
"is an administration tool designed from and for Kevin Veen-Birkenbach.\n\n"
|
|
"Licensed under GNU GENERAL PUBLIC LICENSE Version 3"
|
|
f"{COLOR_RESET}\n"
|
|
)
|