summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2018-12-12 18:23:19 +0000
committerJames Ennis <james.ennis@codethink.com>2019-01-15 16:53:29 +0000
commitaceb3995e84fdbfa2adc6f9e4f61c0ce5a4e1679 (patch)
treebdd7b5c49d6bb789b20dd1c48af0baffb9964b9e
parent94b309c323ecaefb28ac787604a0a35e899d48de (diff)
downloadbuildstream-aceb3995e84fdbfa2adc6f9e4f61c0ce5a4e1679.tar.gz
cli: Split classify_artifacts helper up
Classifying artifact refs is useful for glob expansion even in cases where an element target name would be inappropriate.
-rw-r--r--buildstream/_frontend/cli.py52
1 files changed, 32 insertions, 20 deletions
diff --git a/buildstream/_frontend/cli.py b/buildstream/_frontend/cli.py
index e8e4c8bd6..e3196eaf9 100644
--- a/buildstream/_frontend/cli.py
+++ b/buildstream/_frontend/cli.py
@@ -901,36 +901,48 @@ def workspace_list(app):
#############################################################
# Artifact Commands #
#############################################################
-def _classify_artifacts(names, cas, project_directory):
- element_targets = []
- artifact_refs = []
- element_globs = []
- artifact_globs = []
-
+def _classify_element_targets(names, project_directory):
+ globs = []
+ targets = []
+ unmatched = []
for name in names:
if name.endswith('.bst'):
if any(c in "*?[" for c in name):
- element_globs.append(name)
+ globs.append(name)
else:
- element_targets.append(name)
+ targets.append(name)
else:
- if any(c in "*?[" for c in name):
- artifact_globs.append(name)
- else:
- artifact_refs.append(name)
+ unmatched.append(name)
- if element_globs:
+ if 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)
+ element_path = os.path.relpath(os.path.join(dirpath, filename), start=project_directory)
+ if any(fnmatch(element_path, glob) for glob in globs):
+ targets.append(element_path)
+ return targets, unmatched
+
+
+def _classify_artifact_refs(names, cas):
+ globs = []
+ refs = []
+ for name in names:
+ if any(c in "*?[" for c in name):
+ globs.append(name)
+ else:
+ refs.append(name)
+ if globs:
+ refs.extend(ref for ref in cas.list_refs()
+ if any(fnmatch(ref, glob) for glob in globs))
+ return refs
+
+
+def _classify_artifacts(names, cas, project_directory):
+ targets, unmatched = _classify_element_targets(names, project_directory)
+ refs = _classify_artifact_refs(unmatched, cas)
- if artifact_globs:
- artifact_refs.extend(ref for ref in cas.list_refs()
- if any(fnmatch(ref, glob) for glob in artifact_globs))
+ return targets, refs
- return element_targets, artifact_refs
@cli.group(short_help="Manipulate cached artifacts")