MkosiConfig,
MkosiConfigParser,
SecureBootSignTool,
+ Verb,
)
from mkosi.install import add_dropin_config_from_resource, copy_path
from mkosi.log import Style, color_error, complete_step, die, log_step
InvokingUser,
ManifestFormat,
OutputFormat,
- Verb,
flatten,
flock,
format_bytes,
try_import,
)
-MKOSI_COMMANDS_NEED_BUILD = (Verb.build, Verb.shell, Verb.boot, Verb.qemu, Verb.serve)
-MKOSI_COMMANDS_SUDO = (Verb.shell, Verb.boot)
-
@contextlib.contextmanager
def mount_image(state: MkosiState) -> Iterator[None]:
def needs_build(args: MkosiArgs, config: MkosiConfig) -> bool:
- return args.verb in MKOSI_COMMANDS_NEED_BUILD and (args.force > 0 or not config.output_dir.joinpath(config.output_with_compression).exists())
+ return args.verb.needs_build() and (args.force > 0 or not config.output_dir.joinpath(config.output_with_compression).exists())
@contextlib.contextmanager
def run_verb(args: MkosiArgs, presets: Sequence[MkosiConfig]) -> None:
- if args.verb in MKOSI_COMMANDS_SUDO:
+ if args.verb.needs_sudo():
check_root()
if args.verb == Verb.genkey:
InvokingUser,
ManifestFormat,
OutputFormat,
- Verb,
chdir,
detect_distribution,
flatten,
__version__ = "14"
-MKOSI_COMMANDS_CMDLINE = (Verb.build, Verb.shell, Verb.boot, Verb.qemu, Verb.ssh)
-
ConfigParseCallback = Callable[[str, Optional[str], argparse.Namespace], Any]
ConfigMatchCallback = Callable[[str, str, argparse.Namespace], bool]
ConfigDefaultCallback = Callable[[argparse.Namespace], Any]
+class Verb(enum.Enum):
+ build = "build"
+ clean = "clean"
+ summary = "summary"
+ shell = "shell"
+ boot = "boot"
+ qemu = "qemu"
+ ssh = "ssh"
+ serve = "serve"
+ bump = "bump"
+ help = "help"
+ genkey = "genkey"
+
+ # Defining __str__ is required to get "print_help()" output to include the human readable (values) of Verb.
+ def __str__(self) -> str:
+ return self.value
+
+ def supports_cmdline(self) -> bool:
+ return self in (Verb.build, Verb.shell, Verb.boot, Verb.qemu, Verb.ssh)
+
+ def needs_build(self) -> bool:
+ return self in (Verb.build, Verb.shell, Verb.boot, Verb.qemu, Verb.serve)
+
+ def needs_sudo(self) -> bool:
+ return self in (Verb.shell, Verb.boot)
+
+
class ConfigFeature(enum.Enum):
auto = "auto"
enabled = "enabled"
def load_config(args: argparse.Namespace) -> MkosiConfig:
find_image_version(args)
- if args.cmdline and args.verb not in MKOSI_COMMANDS_CMDLINE:
- die(f"Parameters after verb are only accepted for {' '.join(verb.name for verb in MKOSI_COMMANDS_CMDLINE)}.")
+ if args.cmdline and not args.verb.supports_cmdline():
+ die(f"Arguments after verb are not supported for {args.verb}.")
if shutil.which("bsdtar") and args.distribution == Distribution.openmandriva and args.tar_strip_selinux_context:
die("Sorry, bsdtar on OpenMandriva is incompatible with --tar-strip-selinux-context")
import pytest
-from mkosi.config import MkosiArgs, MkosiConfig, MkosiConfigParser
-from mkosi.util import Compression, Distribution, Verb
+from mkosi.config import MkosiArgs, MkosiConfig, MkosiConfigParser, Verb
+from mkosi.util import Compression, Distribution
@contextmanager