This is an automated email from the ASF dual-hosted git repository. github-bot pushed a commit to branch jennis/push_pull_artifacts in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit aceb3995e84fdbfa2adc6f9e4f61c0ce5a4e1679 Author: Richard Maw <[email protected]> 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 e8e4c8b..e3196ea 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")
