from mkosi.log import ARG_DEBUG, ARG_DEBUG_SANDBOX, ARG_DEBUG_SHELL, complete_step, die
from mkosi.pager import page
from mkosi.run import SandboxProtocol, find_binary, nosandbox, run, sandbox_cmd, workdir
-from mkosi.sandbox import Style, __version__
+from mkosi.sandbox import ANSI_BLUE, ANSI_BOLD, ANSI_RESET, __version__
from mkosi.user import INVOKING_USER
from mkosi.util import (
PathString,
mkosi [options…] {b}help{e}
mkosi -h | --help
mkosi --version
- """).format(b=Style.bold, e=Style.reset),
+ """).format(b=ANSI_BOLD, e=ANSI_RESET),
add_help=False,
allow_abbrev=False,
argument_default=argparse.SUPPRESS,
def bold(s: Any) -> str:
- return f"{Style.bold}{s}{Style.reset}"
+ return f"{ANSI_BOLD}{s}{ANSI_RESET}"
def cat_config(images: Sequence[Config]) -> str:
# Display the paths as relative to ., if underneath.
if path.is_relative_to(Path.cwd()):
path = path.relative_to(Path.cwd())
- print(f"{Style.blue}# {path}{Style.reset}", file=c)
+ print(f"{ANSI_BLUE}# {path}{ANSI_RESET}", file=c)
print(path.read_text(), file=c)
return c.getvalue()
from collections.abc import Iterator
from typing import Any, NoReturn, Optional
-from mkosi.sandbox import Style, terminal_is_dumb
+from mkosi.sandbox import ANSI_BOLD, ANSI_GRAY, ANSI_RED, ANSI_RESET, ANSI_YELLOW, terminal_is_dumb
# This global should be initialized after parsing arguments
ARG_DEBUG = contextvars.ContextVar("debug", default=False)
else:
if not terminal_is_dumb():
print(ConsoleCodes.set_window_title(text), file=sys.stderr, end="")
- logging.info(f"{prefix}{Style.bold}{text}{Style.reset}")
+ logging.info(f"{prefix}{ANSI_BOLD}{text}{ANSI_RESET}")
def log_notice(text: str) -> None:
- logging.info(f"{Style.bold}{text}{Style.reset}")
+ logging.info(f"{ANSI_BOLD}{text}{ANSI_RESET}")
@contextlib.contextmanager
fmt = fmt or "%(message)s"
self.formatters = {
- logging.DEBUG: logging.Formatter(f"‣ {Style.gray}{fmt}{Style.reset}"),
+ logging.DEBUG: logging.Formatter(f"‣ {ANSI_GRAY}{fmt}{ANSI_RESET}"),
logging.INFO: logging.Formatter(f"‣ {fmt}"),
- logging.WARNING: logging.Formatter(f"‣ {Style.yellow}{fmt}{Style.reset}"),
- logging.ERROR: logging.Formatter(f"‣ {Style.red}{fmt}{Style.reset}"),
- logging.CRITICAL: logging.Formatter(f"‣ {Style.red}{Style.bold}{fmt}{Style.reset}"),
+ logging.WARNING: logging.Formatter(f"‣ {ANSI_YELLOW}{fmt}{ANSI_RESET}"),
+ logging.ERROR: logging.Formatter(f"‣ {ANSI_RED}{fmt}{ANSI_RESET}"),
+ logging.CRITICAL: logging.Formatter(f"‣ {ANSI_RED}{ANSI_BOLD}{fmt}{ANSI_RESET}"),
} # fmt: skip
super().__init__(fmt, *args, **kwargs)
return not sys.stdout.isatty() or not sys.stderr.isatty() or os.getenv("TERM", "") == "dumb"
-class Style:
- # fmt: off
- bold: str = "\033[0;1;39m" if not terminal_is_dumb() else ""
- blue: str = "\033[0;1;34m" if not terminal_is_dumb() else ""
- gray: str = "\033[0;38;5;245m" if not terminal_is_dumb() else ""
- red: str = "\033[31;1m" if not terminal_is_dumb() else ""
- yellow: str = "\033[33;1m" if not terminal_is_dumb() else ""
- reset: str = "\033[0m" if not terminal_is_dumb() else ""
- # fmt: on
+# fmt: off
+ANSI_BOLD = "\033[0;1;39m" if not terminal_is_dumb() else ""
+ANSI_BLUE = "\033[0;1;34m" if not terminal_is_dumb() else ""
+ANSI_GRAY = "\033[0;38;5;245m" if not terminal_is_dumb() else ""
+ANSI_RED = "\033[31;1m" if not terminal_is_dumb() else ""
+ANSI_YELLOW = "\033[33;1m" if not terminal_is_dumb() else ""
+ANSI_RESET = "\033[0m" if not terminal_is_dumb() else ""
+# fmt: on
ENOSYS_MSG = f"""\
-{Style.red}mkosi was unable to invoke the {{syscall}}() system call.{Style.reset}
+{ANSI_RED}mkosi was unable to invoke the {{syscall}}() system call.{ANSI_RESET}
This probably means either the system call is not implemented by the running kernel version ({{kver}}) or the
system call is prohibited via seccomp if mkosi is being executed inside a containerized environment.\
"""
UNSHARE_EPERM_MSG = f"""\
-{Style.red}mkosi was forbidden to unshare namespaces{Style.reset}.
+{ANSI_RED}mkosi was forbidden to unshare namespaces{ANSI_RESET}.
This probably means your distribution has restricted unprivileged user namespaces.
Please consult the REQUIREMENTS section of the mkosi man page, e.g. via "mkosi
documentation", for workarounds.\