Add simple fnmatch filtering to spack list.
This commit is contained in:
@@ -22,15 +22,44 @@
|
|||||||
# along with this program; if not, write to the Free Software Foundation,
|
# along with this program; if not, write to the Free Software Foundation,
|
||||||
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
# 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
|
from llnl.util.tty.colify import colify
|
||||||
|
|
||||||
import spack
|
import spack
|
||||||
|
import fnmatch
|
||||||
|
|
||||||
description ="List available spack packages"
|
description ="List available spack packages"
|
||||||
|
|
||||||
def setup_parser(subparser):
|
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):
|
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
|
# 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)
|
||||||
|
Reference in New Issue
Block a user