summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2014-10-06 14:11:19 -0700
committerTodd Gamblin <tgamblin@llnl.gov>2014-10-06 14:11:19 -0700
commit1c60b3967d426a6ebf42304cda113377499ea8fb (patch)
treed6e9db284781fca3c217e4293898c173ea8f13d5
parent4cae48c8df8e637d6fc10a62d84c9408e82cbd2a (diff)
downloadspack-1c60b3967d426a6ebf42304cda113377499ea8fb.tar.gz
spack-1c60b3967d426a6ebf42304cda113377499ea8fb.tar.bz2
spack-1c60b3967d426a6ebf42304cda113377499ea8fb.tar.xz
spack-1c60b3967d426a6ebf42304cda113377499ea8fb.zip
Add simple fnmatch filtering to spack list.
-rw-r--r--lib/spack/spack/cmd/list.py33
1 files changed, 31 insertions, 2 deletions
diff --git a/lib/spack/spack/cmd/list.py b/lib/spack/spack/cmd/list.py
index 2b996371ea..99bc64e991 100644
--- a/lib/spack/spack/cmd/list.py
+++ b/lib/spack/spack/cmd/list.py
@@ -22,15 +22,44 @@
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##############################################################################
+import sys
+import argparse
+import llnl.util.tty as tty
from llnl.util.tty.colify import colify
+
import spack
+import fnmatch
description ="List available spack packages"
def setup_parser(subparser):
- pass
+ subparser.add_argument(
+ 'filter', nargs=argparse.REMAINDER,
+ help='Optional glob patterns to filter results.')
+ subparser.add_argument(
+ '-i', '--insensitive', action='store_true', default=False,
+ help='Filtering will be case insensitive.')
def list(parser, args):
+ # Start with all package names.
+ pkgs = spack.db.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)]
+
+ # sort before displaying.
+ sorted_packages = sorted(pkgs, key=lambda s:s.lower())
+
# Print all the package names in columns
- colify(spack.db.all_package_names())
+ indent=0
+ if sys.stdout.isatty():
+ tty.msg("%d packages." % len(sorted_packages))
+ indent=2
+ colify(sorted_packages, indent=indent)