Let's allow configuring the compression level.
# Note that when compress_output == Compression.none == 0 we don't pass --compress-output which means the
# default compression will get picked. This is exactly what we want so that initrds are always compressed.
*(["--compress-output", str(context.config.compress_output)] if context.config.compress_output else []),
+ "--compress-level", str(context.config.compress_level),
"--with-network", str(context.config.with_network),
"--cache-only", str(context.config.cache_only),
"--output-dir", str(context.workspace / "initrd"),
"""Returns a command suitable for compressing archives."""
if compression == Compression.gz:
- return [gzip_binary(context), "--fast", "--stdout", "-"]
+ return [gzip_binary(context), f"-{context.config.compress_level}" "--stdout", "-"]
elif compression == Compression.xz:
- return ["xz", "--check=crc32", "--fast", "-T0", "--stdout", "-"]
+ return ["xz", "--check=crc32", f"-{context.config.compress_level}", "-T0", "--stdout", "-"]
elif compression == Compression.zstd:
- return ["zstd", "-q", "-T0", "--stdout", "-"]
+ return ["zstd", "-q", f"-{context.config.compress_level}", "-T0", "--stdout", "-"]
else:
die(f"Unknown compression {compression}")
try:
timestamp = int(value)
except ValueError:
- raise ValueError(f"{value} is not a valid timestamp")
+ die(f"{value} is not a valid timestamp")
+
if timestamp < 0:
- raise ValueError(f"{value} is negative")
+ die(f"Source date epoch timestamp cannot be negative (got {value})")
+
return timestamp
+def config_parse_compress_level(value: Optional[str], old: Optional[int]) -> Optional[int]:
+ if not value:
+ return None
+
+ try:
+ level = int(value)
+ except ValueError:
+ die(f"{value} is not a valid compression level")
+
+ if level < 0:
+ die(f"Compression level cannot be negative (got {value})")
+
+ return level
+
+
def config_default_compression(namespace: argparse.Namespace) -> Compression:
if namespace.output_format in (OutputFormat.tar, OutputFormat.cpio, OutputFormat.uki, OutputFormat.esp):
if namespace.distribution.is_centos_variant() and int(namespace.release) <= 8:
manifest_format: list[ManifestFormat]
output: str
compress_output: Compression
+ compress_level: int
output_dir: Optional[Path]
workspace_dir: Optional[Path]
cache_dir: Optional[Path]
default_factory_depends=("distribution", "release", "output_format"),
help="Enable whole-output compression (with images or archives)",
),
+ ConfigSetting(
+ dest="compress_level",
+ metavar="LEVEL",
+ section="Output",
+ parse=config_parse_compress_level,
+ default=3,
+ help="Set the compression level to use",
+ ),
ConfigSetting(
dest="output_dir",
short="-O",
Manifest Formats: {maniformats}
Output: {bold(config.output_with_compression)}
Compression: {config.compress_output}
+ Compression Level: {config.compress_level}
Output Directory: {config.output_dir_or_cwd()}
Workspace Directory: {config.workspace_dir_or_default()}
Cache Directory: {none_to_none(config.cache_dir)}
are not available when this option is used. Implied for `tar`, `cpio`, `uki`,
and `esp`.
+`CompressLevel=`, `--compress-level=`
+
+: Configure the compression level to use. Takes an integer. The possible
+ values depend on the compression being used.
+
`OutputDirectory=`, `--output-dir=`, `-O`
: Path to a directory where to place all generated artifacts. If this is
"CacheOnly": true,
"Checksum": false,
"CleanPackageMetadata": "auto",
+ "CompressLevel": 3,
"CompressOutput": "bz2",
"Credentials": {
"credkey": "credval"
cache_only = True,
checksum = False,
clean_package_metadata = ConfigFeature.auto,
+ compress_level = 3,
compress_output = Compression.bz2,
credentials = {"credkey": "credval"},
dependencies = ("dep1",),