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) output.write(" " * indent)
for col in xrange(cols): for col in xrange(cols):
elt = col * rows + row elt = col * rows + row
output.write(formats[col] % decorator(elts[elt])) output.write(decorator(formats[col] % elts[elt]))
output.write("\n") output.write("\n")
row += 1 row += 1
@ -206,6 +206,25 @@ def colify(elts, **options):
return (config.cols, tuple(config.widths)) 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): def colified(elts, **options):
"""Invokes the colify() function but returns the result as a string """Invokes the colify() function but returns the result as a string
instead of writing it to an output string.""" instead of writing it to an output string."""

View File

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