Skip to content

Commit

Permalink
feat: Add support for mmdebstrap's --skip option
Browse files Browse the repository at this point in the history
fixes #9
Signed-off-by: Benjamin Drung <bdrung@posteo.de>
  • Loading branch information
bdrung committed Dec 5, 2023
1 parent 8fbe0be commit 92a06d6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
12 changes: 12 additions & 0 deletions bdebstrap
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ MMDEBSTRAP_OPTS = {
"mode": str,
"packages": list,
"setup-hooks": list,
"skip": list,
"suite": str,
"target": str,
"variant": str,
Expand Down Expand Up @@ -109,6 +110,8 @@ class Mmdebstrap:
cmd.append(f"--components={','.join(mmdebstrap['components'])}")
if "architectures" in mmdebstrap:
cmd.append(f"--architectures={','.join(mmdebstrap['architectures'])}")
if "skip" in mmdebstrap:
cmd.append(f"--skip={','.join(mmdebstrap['skip'])}")
if "setup-hooks" in mmdebstrap:
cmd += [f"--setup-hook={hook}" for hook in mmdebstrap["setup-hooks"]]
if "extract-hooks" in mmdebstrap:
Expand Down Expand Up @@ -403,6 +406,12 @@ def parse_args(args): # pylint: disable=too-many-statements
action="append",
help="Execute arbitrary COMMAND after all customize hooks have been executed.",
)
parser.add_argument(
"--skip",
metavar="STAGE",
action="append",
help="Comma or whitespace separated list of actions and safety checks to skip.",
)

# Positional arguments from mmdebstrap
parser.add_argument(
Expand Down Expand Up @@ -503,6 +512,7 @@ def parse_args(args): # pylint: disable=too-many-statements
args.essential_hook = sanitize_list(args.essential_hook)
args.customize_hook = sanitize_list(args.customize_hook)
args.cleanup_hook = sanitize_list(args.cleanup_hook)
args.skip = sanitize_list(args.skip)

return args

Expand Down Expand Up @@ -611,6 +621,8 @@ class Config(dict):
self._append_mmdebstrap_option("customize-hooks", args.customize_hook)
if args.cleanup_hook:
self._append_mmdebstrap_option("cleanup-hooks", args.cleanup_hook)
if args.skip:
self._append_mmdebstrap_option("skip", args.skip)
if args.suite:
self._set_mmdebstrap_option("suite", args.suite)
if args.target:
Expand Down
14 changes: 13 additions & 1 deletion bdebstrap.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ bdebstrap - YAML config based multi-mirror Debian chroot creation tool
[**\--architectures** *ARCHITECTURES*]
[**\--setup-hook** *COMMAND*] [**\--extract-hook** *COMMAND*]
[**\--essential-hook** *COMMAND*] [**\--customize-hook** *COMMAND*]
[**\--cleanup-hook** *COMMAND*]
[**\--cleanup-hook** *COMMAND*] [**\--skip** *STAGE*]
[**\--suite** *SUITE*] [**\--target** *TARGET*] [**\--mirrors** *MIRRORS*]
[*SUITE* [*TARGET* [*MIRROR*...]]]

Expand Down Expand Up @@ -171,6 +171,10 @@ output directory as *config.yaml*.
: Execute arbitrary *COMMAND* after all customize hooks have been executed.
This option can be specified multiple times.

**\--skip** *STAGE*
: Comma or whitespace separated list of actions and safety checks to skip.
This option can be specified multiple times.

**\--suite** *SUITE*, *SUITE*
: The suite may be a valid release code name (eg, sid, stretch, jessie) or
a symbolic name (eg, unstable, testing, stable, oldstable).
Expand Down Expand Up @@ -292,6 +296,14 @@ be specified:
directly after all other customize hooks. See **customize-hooks** above.
Additional cleanup hooks can be specified with **\--cleanup-hook**.

**skip**
: list of stages to skip (string). mmdebstrap tries hard to implement
sensible defaults and will try to stop you before shooting yourself in the
foot. This option is for when you are sure you know what you are doing and
allows one to skip certain actions and safety checks. See section
**OPERATION** in mmdebstrap(1) for a list of possible arguments and their
context. Additional stages to skip can be specified with **\--skip**.

**suite**
: String. The suite may be a valid release code name (eg, sid, stretch,
jessie) or a symbolic name (eg, unstable, testing, stable, oldstable). Can
Expand Down
6 changes: 6 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def test_empty_args(self):
"--essential-hook=",
"--extract-hook=",
"--keyring=",
"--skip=",
"--mirrors=",
"--packages=",
"--setup-hook=",
Expand All @@ -81,6 +82,7 @@ def test_empty_args(self):
"mirrors",
"packages",
"setup_hook",
"skip",
},
),
{
Expand All @@ -97,6 +99,7 @@ def test_empty_args(self):
"mirrors": [],
"packages": [],
"setup_hook": [],
"skip": [],
},
)

Expand Down Expand Up @@ -130,6 +133,7 @@ def test_no_args(self):
"packages": None,
"setup_hook": None,
"simulate": False,
"skip": None,
"suite": None,
"target": None,
"tmpdir": None,
Expand Down Expand Up @@ -366,6 +370,7 @@ def test_add_command_line_arguments_no_config(self):
"--hostname",
"cobb",
"--install-recommends",
"--skip=check/signed-by",
"--name",
"ubuntu-24.04",
"--setup-hook",
Expand All @@ -386,6 +391,7 @@ def test_add_command_line_arguments_no_config(self):
"hostname": "cobb",
"install-recommends": True,
"setup-hooks": ['echo root:x:0:0:root:/root:/bin/sh > "$1/etc/passwd"'],
"skip": ["check/signed-by"],
},
"name": "ubuntu-24.04",
},
Expand Down
2 changes: 2 additions & 0 deletions tests/test_mmdebstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ def test_extra_opts(self):
"format": "tar",
"packages": ["bash-completions", "vim"],
"suite": "unstable",
"skip": ["cleanup/apt", "update"],
"target": "example.tar.xz",
}
)
Expand All @@ -148,6 +149,7 @@ def test_extra_opts(self):
"--dpkgopt=force-confold",
"--include=bash-completions,vim",
"--components=main,non-free,contrib",
"--skip=cleanup/apt,update",
'--essential-hook=mkdir -p "$1/tmp/bdebstrap-output"',
"--customize-hook=chroot \"$1\" dpkg-query -f='${Package}\\t${Version}\\n' -W "
'> "$1/tmp/bdebstrap-output/manifest"',
Expand Down

0 comments on commit 92a06d6

Please sign in to comment.