stages: add org.osbuild.xz to compress files
Add a new stage that will take a file from the input and compress it via xz.
This commit is contained in:
parent
5d22a672b4
commit
dfda290d6a
1 changed files with 76 additions and 0 deletions
76
stages/org.osbuild.xz
Executable file
76
stages/org.osbuild.xz
Executable file
|
|
@ -0,0 +1,76 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
"""
|
||||||
|
Compress a file
|
||||||
|
|
||||||
|
Buildhost commands used: `xz`.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import osbuild.api
|
||||||
|
|
||||||
|
|
||||||
|
SCHEMA_2 = r"""
|
||||||
|
"inputs": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": false,
|
||||||
|
"required": ["file"],
|
||||||
|
"properties": {
|
||||||
|
"file": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"options": {
|
||||||
|
"additionalProperties": false,
|
||||||
|
"required": ["filename"],
|
||||||
|
"properties": {
|
||||||
|
"filename": {
|
||||||
|
"description": "Filename to use for the compressed file",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def parse_input(inputs):
|
||||||
|
image = inputs["file"]
|
||||||
|
files = image["data"]["files"]
|
||||||
|
assert len(files) == 1
|
||||||
|
|
||||||
|
filename, _ = files.popitem()
|
||||||
|
filepath = os.path.join(image["path"], filename)
|
||||||
|
return filepath
|
||||||
|
|
||||||
|
|
||||||
|
def main(inputs, output, options):
|
||||||
|
filename = options["filename"].lstrip("/")
|
||||||
|
|
||||||
|
source = parse_input(inputs)
|
||||||
|
target = os.path.join(output, filename)
|
||||||
|
|
||||||
|
with open(target, "w") as f:
|
||||||
|
|
||||||
|
env = {
|
||||||
|
"XZ_OPT": "--threads 0"
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd = [
|
||||||
|
"xz", "--keep", "--stdout", "-0", source
|
||||||
|
]
|
||||||
|
|
||||||
|
subprocess.run(
|
||||||
|
cmd, stdout=f, check=True, env=env
|
||||||
|
)
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
args = osbuild.api.arguments()
|
||||||
|
r = main(args["inputs"], args["tree"], args["options"])
|
||||||
|
sys.exit(r)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue