summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTom Scogland <scogland1@llnl.gov>2016-06-17 12:00:35 -0700
committerTom Scogland <scogland1@llnl.gov>2016-06-17 12:00:35 -0700
commita4ac99877a512249fa7d126f48716d590cfa80a9 (patch)
tree2bf55c9bcc2c27ff063f3a94ebbbd7e07c1232bc /lib
parentf351e011d1f91372492651829b9dd82d81cd191d (diff)
downloadspack-a4ac99877a512249fa7d126f48716d590cfa80a9.tar.gz
spack-a4ac99877a512249fa7d126f48716d590cfa80a9.tar.bz2
spack-a4ac99877a512249fa7d126f48716d590cfa80a9.tar.xz
spack-a4ac99877a512249fa7d126f48716d590cfa80a9.zip
cmd/list: adding description search and glob by default
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/cmd/list.py37
1 files changed, 29 insertions, 8 deletions
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 @@ import argparse
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())