debian-forge/assemblers/org.osbuild.tar
Lars Karlitski e590dee93b assemblers/tar: fix compression
Commit 283281f broke compression by appending the argument last to the
tar command line. It needs to appear before the file.

Fix that and add a test.

[teg: add minor fix]
2019-12-10 12:07:08 +01:00

58 lines
1.7 KiB
Python
Executable file

#!/usr/bin/python3
import json
import subprocess
import sys
STAGE_DESC = "Assemble a tar archive"
STAGE_INFO = """
Assembles the tree into a tar archive named `filename`.
Uses the buildhost's `tar` command, like: `tar -cf $FILENAME -C $TREE`
If the `compression` option is given, the archive will be compressed by passing
the `--{compression}` option to `tar`. (This option is non-standard and might
not work for anything other than GNU tar.)
Known options for `compression`: "bzip2", "xz", "lzip", "lzma", "lzop", "gzip".
Note that using `compression` does not add an extension to `filename`, so the
caller is responsible for making sure that `compression` and `filename` match.
Buildhost commands used: `tar` and any named `compression` program.
"""
STAGE_OPTS = """
"required": ["filename"],
"properties": {
"filename": {
"description": "Filename for tar archive",
"type": "string"
},
"compression": {
"description": "Name of compression program",
"type": "string",
"enum": ["bzip2", "xz", "lzip", "lzma", "lzop", "gzip"]
}
}
"""
def main(tree, output_dir, options):
filename = options["filename"]
compression = options.get("compression")
extra_args = []
if compression is not None:
if compression not in {"bzip2", "xz", "lzip", "lzma", "lzop", "gzip"}:
return 1
extra_args.append(f"--{compression}")
subprocess.run(["tar", *extra_args, "-cf", f"{output_dir}/{filename}", "-C", tree, "."],
stdout=subprocess.DEVNULL, check=True)
return 0
if __name__ == '__main__':
args = json.load(sys.stdin)
r = main(args["tree"], args["output_dir"], args["options"])
sys.exit(r)