Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions mkosi/burn.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: LGPL-2.1-or-later

import logging
import os
import sys

Expand All @@ -21,6 +22,23 @@ def run_burn(args: Args, config: Config) -> None:
if len(args.cmdline) != 1:
die("Expected device argument.")

device = args.cmdline[0]
lsblk_command = [
"lsblk",
"-o", "PATH,LABEL,PARTLABEL,FSTYPE,SIZE,HOTPLUG,MOUNTPOINTS",
"--paths",
device,
] # fmt: skip

logging.info(f"About to burn image to device: {device}")
logging.info("The following block device layout will be overwritten:")
run(lsblk_command)

if args.interactive:
reply = input("Do you want to continue? [y/N] ").strip().lower()
if reply not in ("y", "yes"):
die("Aborting burning image to device.")

cmd = [
"systemd-repart",
"--no-pager",
Expand Down
10 changes: 10 additions & 0 deletions mkosi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1935,6 +1935,7 @@ class Args:
json: bool
wipe_build_dir: bool
rerun_build_scripts: bool
interactive: bool

@classmethod
def default(cls) -> "Args":
Expand Down Expand Up @@ -4682,6 +4683,12 @@ def create_argument_parser(chdir: bool = True) -> argparse.ArgumentParser:
action="store_true",
default=False,
)
parser.add_argument(
"--interactive",
help="Prompt for confirmation before burning the image to a device.",
action="store_true",
default=False,
)
# These can be removed once mkosi v15 is available in LTS distros and compatibility with <= v14
# is no longer needed in build infrastructure (e.g.: OBS).
parser.add_argument(
Expand Down Expand Up @@ -5466,6 +5473,9 @@ def parse_config(
if args.rerun_build_scripts and args.force:
die("--force cannot be used together with --rerun-build-scripts")

if args.interactive and args.verb != Verb.burn:
die("--interactive can only be used with the 'burn' command")

if args.cmdline and not args.verb.supports_cmdline():
die(f"Arguments after verb are not supported for the '{args.verb}' command")

Expand Down
15 changes: 15 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,21 @@ def test_parse_load_verb(tmp_path: Path) -> None:
parse_config(["invalid"])


def test_interactive_flag(tmp_path: Path) -> None:
with chdir(tmp_path):
args, _, _ = parse_config(["burn"])
assert not args.interactive

args, _, _ = parse_config(["burn", "--interactive"])
assert args.interactive


def test_interactive_only_with_burn(tmp_path: Path) -> None:
with chdir(tmp_path):
with pytest.raises(SystemExit):
parse_config(["build", "--interactive"])


def test_os_distribution(tmp_path: Path) -> None:
with chdir(tmp_path):
for dist in Distribution:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def test_args(path: Optional[Path]) -> None:
"Force": 9001,
"GenkeyCommonName": "test",
"GenkeyValidDays": "100",
"Interactive": false,
"Json": false,
"Pager": true,
"RerunBuildScripts": true,
Expand All @@ -92,6 +93,7 @@ def test_args(path: Optional[Path]) -> None:
force=9001,
genkey_common_name="test",
genkey_valid_days="100",
interactive=False,
json=False,
pager=True,
rerun_build_scripts=True,
Expand Down
Loading