diff --git a/lib/spack/spack/cmd/list.py b/lib/spack/spack/cmd/list.py index 1e3699cee0..5406283b05 100644 --- a/lib/spack/spack/cmd/list.py +++ b/lib/spack/spack/cmd/list.py @@ -28,7 +28,7 @@ from llnl.util.tty.colify import colify import spack -import fnmatch +import fnmatch, re description ="List available spack packages" @@ -39,20 +39,41 @@ def setup_parser(subparser): subparser.add_argument( '-i', '--insensitive', action='store_true', default=False, help='Filtering will be case insensitive.') + subparser.add_argument( + '-s', '--search_description', action='store_true', default=False, + help='Filtering will also search the description for a match.') def list(parser, args): # Start with all package names. - pkgs = spack.repo.all_package_names() + pkgs = set(spack.repo.all_package_names()) # filter if a filter arg was provided if args.filter: - def match(p, f): - if args.insensitive: - p = p.lower() - f = f.lower() - return fnmatch.fnmatchcase(p, f) - pkgs = [p for p in pkgs if any(match(p, f) for f in args.filter)] + filters = [] + for f in args.filter: + if '*' not in f and '?' not in f: + filters.append('*' + f + '*') + else: + filters.append(f) + + res = [re.compile(fnmatch.translate(f), + flags=re.I if args.insensitive else 0) + for f in filters] + + if args.search_description: + def match(p, f): + if f.match(p): + return True + + pkg = spack.repo.get(p) + if pkg.__doc__: + return f.match(pkg.__doc__) + return False + else: + def match(p, f): + return f.match(p) + pkgs = [p for p in pkgs if any(match(p, f) for f in res)] # sort before displaying. sorted_packages = sorted(pkgs, key=lambda s:s.lower())