summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2018-11-01 15:23:20 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2018-12-12 16:32:41 +0000
commitb3dceb16cc56bd8d1c43a7d14e2c0e98d39769c4 (patch)
tree04ad44e0ab24758dc28fe43952d05deb8ce01c9d
parent3697a61107ea484f6a119ab0275441b75292acce (diff)
downloadbuildstream-b3dceb16cc56bd8d1c43a7d14e2c0e98d39769c4.tar.gz
cli: Add artifact command group
-rw-r--r--buildstream/_frontend/cli.py42
-rw-r--r--tests/completions/completions.py1
2 files changed, 43 insertions, 0 deletions
diff --git a/buildstream/_frontend/cli.py b/buildstream/_frontend/cli.py
index 7673a2d71..67958385c 100644
--- a/buildstream/_frontend/cli.py
+++ b/buildstream/_frontend/cli.py
@@ -1,5 +1,6 @@
import os
import sys
+from fnmatch import fnmatch
import click
from .. import _yaml
@@ -934,3 +935,44 @@ def workspace_list(app):
with app.initialized():
app.stream.workspace_list()
+
+
+#############################################################
+# Artifact Commands #
+#############################################################
+def _classify_artifacts(names, cas, project_directory):
+ element_targets = []
+ artifact_refs = []
+ element_globs = []
+ artifact_globs = []
+
+ for name in names:
+ if name.endswith('.bst'):
+ if any(c in "*?[" for c in name):
+ element_globs.append(name)
+ else:
+ element_targets.append(name)
+ else:
+ if any(c in "*?[" for c in name):
+ artifact_globs.append(name)
+ else:
+ artifact_refs.append(name)
+
+ if element_globs:
+ for dirpath, _, filenames in os.walk(project_directory):
+ for filename in filenames:
+ element_path = os.path.join(dirpath, filename).lstrip(project_directory).lstrip('/')
+ if any(fnmatch(element_path, glob) for glob in element_globs):
+ element_targets.append(element_path)
+
+ if artifact_globs:
+ artifact_refs.extend(ref for ref in cas.list_refs()
+ if any(fnmatch(ref, glob) for glob in artifact_globs))
+
+ return element_targets, artifact_refs
+
+
+@cli.group(short_help="Manipulate cached artifacts")
+def artifact():
+ """Manipulate cached artifacts"""
+ pass
diff --git a/tests/completions/completions.py b/tests/completions/completions.py
index 9b32baadd..f810c4f08 100644
--- a/tests/completions/completions.py
+++ b/tests/completions/completions.py
@@ -6,6 +6,7 @@ from tests.testutils import cli
DATA_DIR = os.path.dirname(os.path.realpath(__file__))
MAIN_COMMANDS = [
+ 'artifact ',
'build ',
'checkout ',
'fetch ',