diff options
author | Rebecca Grayson <becky.grayson1@hotmail.co.uk> | 2019-06-27 11:55:18 +0100 |
---|---|---|
committer | Rebecca Grayson <becky.grayson1@hotmail.co.uk> | 2019-07-16 15:35:42 +0000 |
commit | d14ce3cacdb5c1dfce396b64061bb4b8b554a1dc (patch) | |
tree | 3a622c45e16bbe077d31ae9a133655a3ec1bd9a1 /src/buildstream/_stream.py | |
parent | cf3a1f6248fa6c2784020ab8d91b42fe5ed29779 (diff) | |
download | buildstream-d14ce3cacdb5c1dfce396b64061bb4b8b554a1dc.tar.gz |
Allowing tar files to be compressedbecky/tar_compression
Changes made to cli.py and _stream.py in order to support tar
compression. Compression flag has been added, which overrides any file
extensions given. Where no compression or file extension provided,
default to uncompressed .tar.
Diffstat (limited to 'src/buildstream/_stream.py')
-rw-r--r-- | src/buildstream/_stream.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/buildstream/_stream.py b/src/buildstream/_stream.py index 3c32ff616..bc0f55009 100644 --- a/src/buildstream/_stream.py +++ b/src/buildstream/_stream.py @@ -512,8 +512,9 @@ class Stream(): scope=Scope.RUN, integrate=True, hardlinks=False, - tar=False, - pull=False): + compression='', + pull=False, + tar=False): # if pulling we need to ensure dependency artifacts are also pulled selection = PipelineSelection.RUN if pull else PipelineSelection.NONE @@ -552,21 +553,23 @@ class Stream(): .format(e)) from e else: if location == '-': + mode = 'w|' + compression with target.timed_activity("Creating tarball"): # Save the stdout FD to restore later saved_fd = os.dup(sys.stdout.fileno()) try: with os.fdopen(sys.stdout.fileno(), 'wb') as fo: - with tarfile.open(fileobj=fo, mode="w|") as tf: + with tarfile.open(fileobj=fo, mode=mode) as tf: sandbox_vroot.export_to_tar(tf, '.') finally: # No matter what, restore stdout for further use os.dup2(saved_fd, sys.stdout.fileno()) os.close(saved_fd) else: + mode = 'w:' + compression with target.timed_activity("Creating tarball '{}'" .format(location)): - with tarfile.open(location, "w:") as tf: + with tarfile.open(location, mode=mode) as tf: sandbox_vroot.export_to_tar(tf, '.') except BstError as e: |