summaryrefslogtreecommitdiff
path: root/src/buildstream/_frontend/cli.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/buildstream/_frontend/cli.py')
-rw-r--r--src/buildstream/_frontend/cli.py48
1 files changed, 31 insertions, 17 deletions
diff --git a/src/buildstream/_frontend/cli.py b/src/buildstream/_frontend/cli.py
index 3af4121ea..bf92161bf 100644
--- a/src/buildstream/_frontend/cli.py
+++ b/src/buildstream/_frontend/cli.py
@@ -10,6 +10,7 @@ from .. import _yaml
from .._exceptions import BstError, LoadError, AppError
from .._versions import BST_FORMAT_VERSION
from .complete import main_bashcomplete, complete_path, CompleteUnhandled
+from ..utils import _get_compression, UtilError
##################################################################
@@ -970,6 +971,9 @@ def artifact():
help="Create a tarball from the artifact contents instead "
"of a file tree. If LOCATION is '-', the tarball "
"will be dumped to the standard output.")
+@click.option('--compression', default=None,
+ type=click.Choice(['gz', 'xz', 'bz2']),
+ help="The compression option of the tarball created.")
@click.option('--pull', 'pull_', default=False, is_flag=True,
help="Whether to pull the artifact if it's missing or "
"incomplete.")
@@ -979,7 +983,7 @@ def artifact():
@click.argument('element', required=False,
type=click.Path(readable=False))
@click.pass_obj
-def artifact_checkout(app, force, deps, integrate, hardlinks, tar, pull_, directory, element):
+def artifact_checkout(app, force, deps, integrate, hardlinks, tar, compression, pull_, directory, element):
"""Checkout contents of an artifact
When this command is executed from a workspace directory, the default
@@ -991,25 +995,34 @@ def artifact_checkout(app, force, deps, integrate, hardlinks, tar, pull_, direct
click.echo("ERROR: options --hardlinks and --tar conflict", err=True)
sys.exit(-1)
- if not tar and not directory:
- click.echo("ERROR: One of --directory or --tar must be provided", err=True)
- sys.exit(-1)
-
if tar and directory:
click.echo("ERROR: options --directory and --tar conflict", err=True)
sys.exit(-1)
- if tar is not None:
- location = tar
- tar = True
- else:
- if directory is None:
- location = os.path.abspath(os.path.join(os.getcwd(), element))
+ if not tar:
+ if compression:
+ click.echo("ERROR: --compression can only be provided if --tar is provided", err=True)
+ sys.exit(-1)
else:
- location = directory
- if location[-4:] == '.bst':
- location = location[:-4]
- tar = False
+ if directory is None:
+ location = os.path.abspath(os.path.join(os.getcwd(), element))
+ else:
+ location = directory
+ if location[-4:] == '.bst':
+ location = location[:-4]
+ tar = False
+ else:
+ location = tar
+ try:
+ inferred_compression = _get_compression(tar)
+ except UtilError as e:
+ click.echo("ERROR: Invalid file extension given with '--tar': {}".format(e), err=True)
+ sys.exit(-1)
+ if compression and inferred_compression != '' and inferred_compression != compression:
+ click.echo("WARNING: File extension and compression differ."
+ "File extension has been overridden by --compression", err=True)
+ if not compression:
+ compression = inferred_compression
if deps == "build":
scope = Scope.BUILD
@@ -1030,8 +1043,9 @@ def artifact_checkout(app, force, deps, integrate, hardlinks, tar, pull_, direct
scope=scope,
integrate=True if integrate is None else integrate,
hardlinks=hardlinks,
- tar=tar,
- pull=pull_)
+ pull=pull_,
+ compression=compression,
+ tar=bool(tar))
################################################################