stages/org.osbuild.gzip: add compression level option

Allow compression level to be specified instead of defaulting to 1. This is needed for CoreOS Assembler.
This commit is contained in:
Luke Yang 2024-02-21 10:55:49 -05:00 committed by Simon de Vlieger
parent 30f740ec9f
commit cfaabe618f
3 changed files with 12 additions and 2 deletions

View file

@ -30,6 +30,13 @@ SCHEMA_2 = r"""
"filename": { "filename": {
"description": "Filename to use for the compressed file", "description": "Filename to use for the compressed file",
"type": "string" "type": "string"
},
"level": {
"description": "Compression level",
"type": "integer",
"minimum": 1,
"maximum": 9,
"default": 1
} }
} }
} }
@ -48,13 +55,14 @@ def parse_input(inputs):
def main(inputs, output, options): def main(inputs, output, options):
filename = options["filename"].lstrip("/") filename = options["filename"].lstrip("/")
level = options.get("level", 1)
source = parse_input(inputs) source = parse_input(inputs)
target = os.path.join(output, filename) target = os.path.join(output, filename)
with open(target, "w", encoding="utf8") as f: with open(target, "w", encoding="utf8") as f:
cmd = [ cmd = [
"gzip", "--no-name", "--stdout", "-1", source "gzip", "--no-name", "--stdout", f"-{level}", source
] ]
subprocess.run( subprocess.run(

View file

@ -883,7 +883,8 @@
} }
}, },
"options": { "options": {
"filename": "compressed.gz" "filename": "compressed.gz",
"level": 9
} }
} }
] ]

View file

@ -25,3 +25,4 @@ pipelines:
sha256:f950375066d74787f31cbd8f9f91c71819357cad243fb9d4a0d9ef4fa76709e0: {} sha256:f950375066d74787f31cbd8f9f91c71819357cad243fb9d4a0d9ef4fa76709e0: {}
options: options:
filename: compressed.gz filename: compressed.gz
level: 9