From 40b4fa544362d2942ef7663c7fc809c1f5ef591b Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Mon, 1 Dec 2014 23:14:06 -0800 Subject: Better spack find view. --- lib/spack/llnl/util/tty/colify.py | 21 +++++++++++- lib/spack/spack/cmd/find.py | 70 ++++++++++++++++++++------------------- 2 files changed, 56 insertions(+), 35 deletions(-) diff --git a/lib/spack/llnl/util/tty/colify.py b/lib/spack/llnl/util/tty/colify.py index 2c93eaadd5..5c5c6077ec 100644 --- a/lib/spack/llnl/util/tty/colify.py +++ b/lib/spack/llnl/util/tty/colify.py @@ -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.""" diff --git a/lib/spack/spack/cmd/find.py b/lib/spack/spack/cmd/find.py index 2238484a21..c0a3162429 100644 --- a/lib/spack/spack/cmd/find.py +++ b/lib/spack/spack/cmd/find.py @@ -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) - - specs = index[architecture][compiler] - specs.sort() - - 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) - - 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 - - for spec in specs: - format = '$-' + str(max_len) + '_$@$+$#' - print " " + spec.format(format, color=True) + 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() + + 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) + + 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 + + colify((s.format('$-_$@$+$#') for s in specs), decorator=spack.spec.colorize_spec) -- cgit v1.2.3-70-g09d2