def match_downloaded_specs(pkgs, allow_multiple_matches=False, force=False, other_arch=False): """Returns a list of specs matching the not necessarily concretized specs given from cli Args: specs: list of specs to be matched against buildcaches on mirror allow_multiple_matches : if True multiple matches are admitted Return: list of specs """ # List of specs that match expressions given via command line specs_from_cli = [] has_errors = False try: specs = bindist.update_cache_and_get_specs() except bindist.FetchCacheError as e: tty.error(e) if not other_arch: arch = spack.spec.Spec.default_arch() specs = [s for s in specs if s.satisfies(arch)] for pkg in pkgs: matches = [] tty.msg("buildcache spec(s) matching %s \n" % pkg) for spec in sorted(specs): if pkg.startswith('/'): pkghash = pkg.replace('/', '') if spec.dag_hash().startswith(pkghash): matches.append(spec) else: if spec.satisfies(pkg): matches.append(spec) # For each pkg provided, make sure it refers to only one package. # Fail and ask user to be unambiguous if it doesn't if not allow_multiple_matches and len(matches) > 1: tty.error('%s matches multiple downloaded packages:' % pkg) for match in matches: tty.msg('"%s"' % match.format()) has_errors = True # No downloaded package matches the query if len(matches) == 0: tty.error('%s does not match any downloaded packages.' % pkg) has_errors = True specs_from_cli.extend(matches) if has_errors: tty.die('use one of the matching specs above') return specs_from_cli
def listspecs(args): """list binary packages available from mirrors""" specs = bindist.update_cache_and_get_specs() if not args.allarch: arch = spack.architecture.default_arch().to_spec() specs = [s for s in specs if s.satisfies(arch)] if args.specs: constraints = set(args.specs) specs = [s for s in specs if any(s.satisfies(c) for c in constraints)] if sys.stdout.isatty(): builds = len(specs) tty.msg("%s." % plural(builds, 'cached build')) if not builds and not args.allarch: tty.msg("You can query all available architectures with:", "spack buildcache list --allarch") display_specs(specs, args, all_headers=True)