extensions: support only showing a subset of information

This commit is contained in:
Ben Boeckel 2017-10-06 13:12:40 -04:00 committed by scheibelp
parent b7ec870c3b
commit 4511d9d924

View File

@ -49,6 +49,10 @@ def setup_parser(subparser):
format_group.add_argument( format_group.add_argument(
'-d', '--deps', action='store_const', dest='mode', const='deps', '-d', '--deps', action='store_const', dest='mode', const='deps',
help='show full dependency DAG of extensions') help='show full dependency DAG of extensions')
subparser.add_argument(
'-s', '--show', dest='show', metavar='TYPE', type=str,
default='all',
help="one of packages, installed, activated, all")
subparser.add_argument( subparser.add_argument(
'-v', '--view', metavar='VIEW', type=str, '-v', '--view', metavar='VIEW', type=str,
help="the view to operate on") help="the view to operate on")
@ -62,6 +66,24 @@ def extensions(parser, args):
if not args.spec: if not args.spec:
tty.die("extensions requires a package spec.") tty.die("extensions requires a package spec.")
show_packages = False
show_installed = False
show_activated = False
show_all = False
if args.show == 'packages':
show_packages = True
elif args.show == 'installed':
show_installed = True
elif args.show == 'activated':
show_activated = True
elif args.show == 'all':
show_packages = True
show_installed = True
show_activated = True
show_all = True
else:
tty.die('unrecognized show type: %s' % args.show)
# #
# Checks # Checks
# #
@ -80,40 +102,46 @@ def extensions(parser, args):
if not args.mode: if not args.mode:
args.mode = 'short' args.mode = 'short'
# if show_packages:
# List package names of extensions #
extensions = spack.repo.extensions_for(spec) # List package names of extensions
if not extensions: extensions = spack.repo.extensions_for(spec)
tty.msg("%s has no extensions." % spec.cshort_spec) if not extensions:
return tty.msg("%s has no extensions." % spec.cshort_spec)
tty.msg(spec.cshort_spec) else:
tty.msg("%d extensions:" % len(extensions)) tty.msg(spec.cshort_spec)
colify(ext.name for ext in extensions) tty.msg("%d extensions:" % len(extensions))
colify(ext.name for ext in extensions)
layout = spack.store.extensions layout = spack.store.extensions
if args.view is not None: if args.view is not None:
layout = YamlViewExtensionsLayout(args.view, spack.store.layout) layout = YamlViewExtensionsLayout(args.view, spack.store.layout)
# if show_installed:
# List specs of installed extensions. #
# # List specs of installed extensions.
installed = [s.spec #
for s in spack.store.db.installed_extensions_for(spec)] installed = [s.spec
for s in spack.store.db.installed_extensions_for(spec)]
print if show_all:
if not installed: print
tty.msg("None installed.") if not installed:
tty.msg("%d installed:" % len(installed)) tty.msg("None installed.")
spack.cmd.find.display_specs(installed, mode=args.mode) else:
tty.msg("%d installed:" % len(installed))
spack.cmd.find.display_specs(installed, mode=args.mode)
# if show_activated:
# List specs of activated extensions. #
# # List specs of activated extensions.
activated = layout.extension_map(spec) #
print activated = layout.extension_map(spec)
if not activated: if show_all:
tty.msg("None activated.") print
return if not activated:
tty.msg("%d currently activated:" % len(activated)) tty.msg("None activated.")
spack.cmd.find.display_specs( else:
activated.values(), mode=args.mode, long=args.long) tty.msg("%d currently activated:" % len(activated))
spack.cmd.find.display_specs(
activated.values(), mode=args.mode, long=args.long)