You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by no...@apache.org on 2020/12/29 12:25:23 UTC
[buildstream] 01/06: cli: Split classify_artifacts helper up
This is an automated email from the ASF dual-hosted git repository.
not-in-ldap pushed a commit to branch jennis/deprecate_bst_checkout
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 1c92ee41e412ee0433a786e1a57194052dddc2ef
Author: Richard Maw <ri...@codethink.co.uk>
AuthorDate: Wed Dec 12 18:23:19 2018 +0000
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.
---
buildstream/_frontend/cli.py | 52 +++++++++++++++++++++++++++-----------------
1 file changed, 32 insertions(+), 20 deletions(-)
diff --git a/buildstream/_frontend/cli.py b/buildstream/_frontend/cli.py
index bdcf3ca..ae64afa 100644
--- a/buildstream/_frontend/cli.py
+++ b/buildstream/_frontend/cli.py
@@ -973,36 +973,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")