if not src.is_file():
return
- if config.compress_output == Compression.none:
+ if not config.compress_output:
# If we shan't compress, then at least make the output file sparse
with complete_step(f"Digging holes into output file {src}…"):
run(["fallocate", "--dig-holes", src], user=uid, group=gid)
Output Signature: {none_to_na(config.output_signature if config.sign else None)}
Output nspawn Settings: {none_to_na(config.output_nspawn_settings if config.nspawn_settings is not None else None)}
Incremental: {yes_no(config.incremental)}
- Compression: {config.compress_output.name}
+ Compression: {config.compress_output}
Bootable: {config.bootable}
Kernel Command Line: {" ".join(config.kernel_command_line)}
UEFI SecureBoot: {yes_no(config.secure_boot)}
@property
def output_compressed(self) -> Path:
- if self.compress_output == Compression.none:
+ if not self.compress_output:
return self.output
- return self.output.parent / f"{self.output.name}.{self.compress_output.name}"
+ return self.output.parent / f"{self.output.name}.{self.compress_output}"
def output_paths(self) -> tuple[Path, ...]:
return (
opname = "acquire shell" if args.verb == Verb.shell else "boot"
if args.output_format in (OutputFormat.tar, OutputFormat.cpio):
die(f"Sorry, can't {opname} with a {args.output_format} archive.")
- if args.compress_output != Compression.none:
+ if args.compress_output:
die(f"Sorry, can't {opname} with a compressed image.")
if args.repo_dirs and not (
return self.name
-class Compression(str, enum.Enum):
- none = "none"
+class Compression(enum.Enum):
+ none = None
zst = "zst"
xz = "xz"
bz2 = "bz2"
lz4 = "lz4"
lzma = "lzma"
+ def __str__(self) -> str:
+ return str(self.value).lower()
+
+ def __bool__(self) -> bool:
+ return bool(self.value)
+
def dictify(f: Callable[..., Iterator[tuple[T, V]]]) -> Callable[..., dict[T, V]]:
def wrapper(*args: Any, **kwargs: Any) -> dict[T, V]:
import os
from mkosi.util import (
+ Compression,
Distribution,
PackageType,
set_umask,
assert tmp1 == 0o767
assert tmp2 == 0o757
assert tmp3 == 0o777
+
+
+def test_compression_enum_creation() -> None:
+ assert Compression(None) == Compression.none
+ assert Compression("zst") == Compression.zst
+ assert Compression("xz") == Compression.xz
+ assert Compression("bz2") == Compression.bz2
+ assert Compression("gz") == Compression.gz
+ assert Compression("lz4") == Compression.lz4
+ assert Compression("lzma") == Compression.lzma
+
+
+def test_compression_enum_bool() -> None:
+ assert bool(Compression.none) == False
+ assert bool(Compression.zst) == True
+ assert bool(Compression.xz) == True
+ assert bool(Compression.bz2) == True
+ assert bool(Compression.gz) == True
+ assert bool(Compression.lz4) == True
+ assert bool(Compression.lzma) == True
+
+
+def test_compression_enum_str() -> None:
+ assert str(Compression.none) == "none"
+ assert str(Compression.zst) == "zst"
+ assert str(Compression.xz) == "xz"
+ assert str(Compression.bz2) == "bz2"
+ assert str(Compression.gz) == "gz"
+ assert str(Compression.lz4) == "lz4"
+ assert str(Compression.lzma) == "lzma"