Better spack find view.

This commit is contained in:
Todd Gamblin 2014-12-01 23:14:06 -08:00
parent e15316e825
commit 40b4fa5443
2 changed files with 50 additions and 29 deletions

View File

@ -196,7 +196,7 @@ def colify(elts, **options):
output.write(" " * indent)
for col in xrange(cols):
elt = col * rows + row
output.write(formats[col] % decorator(elts[elt]))
output.write(decorator(formats[col] % elts[elt]))
output.write("\n")
row += 1
@ -206,6 +206,25 @@ def colify(elts, **options):
return (config.cols, tuple(config.widths))
def colify_table(table, **options):
if table is None:
raise TypeError("Can't call colify_table on NoneType")
elif not table or not table[0]:
raise ValueError("Table is empty in colify_table!")
columns = len(table[0])
def transpose():
for i in xrange(columns):
for row in table:
yield row[i]
if 'cols' in options:
raise ValueError("Cannot override columsn in colify_table.")
options['cols'] = columns
colify(transpose(), **options)
def colified(elts, **options):
"""Invokes the colify() function but returns the result as a string
instead of writing it to an output string."""

View File

@ -24,13 +24,14 @@
##############################################################################
import sys
import collections
import itertools
from external import argparse
from StringIO import StringIO
import llnl.util.tty as tty
from llnl.util.tty.colify import colify
from llnl.util.tty.colify import *
from llnl.util.tty.color import *
from llnl.util.lang import partition_list, index_by
from llnl.util.lang import *
import spack
import spack.spec
@ -65,39 +66,40 @@ def find(parser, args):
if not query_specs:
return
specs = [s for s in spack.db.installed_package_specs()
if not query_specs or any(s.satisfies(q) for q in query_specs)]
# Get all the specs the user asked for
if not query_specs:
specs = set(spack.db.installed_package_specs())
else:
results = [set(spack.db.get_installed(qs)) for qs in query_specs]
specs = set.union(*results)
# Make a dict with specs keyed by architecture and compiler.
index = index_by(specs, 'architecture', 'compiler')
index = index_by(specs, ('architecture', 'compiler'))
# Traverse the index and print out each package
for architecture in index:
tty.hline(architecture, char='=', color=spack.spec.architecture_color)
for compiler in index[architecture]:
tty.hline(compiler, char='-', color=spack.spec.compiler_color)
for i, (architecture, compiler) in enumerate(sorted(index)):
if i > 0: print
tty.hline("%s / %s" % (compiler, architecture), char='-')
specs = index[architecture][compiler]
specs.sort()
specs = index[(architecture, compiler)]
specs.sort()
abbreviated = [s.format('$_$@$+$#', color=True) for s in specs]
abbreviated = [s.format('$_$@$+$#', color=True) for s in specs]
if args.paths:
# Print one spec per line along with prefix path
width = max(len(s) for s in abbreviated)
width += 2
format = " %-{}s%s".format(width)
if args.paths:
# Print one spec per line along with prefix path
width = max(len(s) for s in abbreviated)
width += 2
format = " %-{}s%s".format(width)
for abbrv, spec in zip(abbreviated, specs):
print format % (abbrv, spec.prefix)
for abbrv, spec in zip(abbreviated, specs):
print format % (abbrv, spec.prefix)
elif args.full_specs:
for spec in specs:
print spec.tree(indent=4, format='$_$@$+', color=True),
else:
max_len = max([len(s.name) for s in specs])
max_len += 4
elif args.full_specs:
for spec in specs:
print spec.tree(indent=4, format='$_$@$+', color=True),
else:
max_len = max([len(s.name) for s in specs])
max_len += 4
for spec in specs:
format = '$-' + str(max_len) + '_$@$+$#'
print " " + spec.format(format, color=True)
colify((s.format('$-_$@$+$#') for s in specs), decorator=spack.spec.colorize_spec)