summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/cmd/find.py36
-rw-r--r--lib/spack/spack/spec.py12
2 files changed, 32 insertions, 16 deletions
diff --git a/lib/spack/spack/cmd/find.py b/lib/spack/spack/cmd/find.py
index 70b10edb4e..15c1cc9196 100644
--- a/lib/spack/spack/cmd/find.py
+++ b/lib/spack/spack/cmd/find.py
@@ -41,9 +41,6 @@ description ="Find installed spack packages"
def setup_parser(subparser):
format_group = subparser.add_mutually_exclusive_group()
format_group.add_argument(
- '-l', '--long', action='store_const', dest='mode', const='long',
- help='Show dependency hashes as well as versions.')
- format_group.add_argument(
'-p', '--paths', action='store_const', dest='mode', const='paths',
help='Show paths to package install directories')
format_group.add_argument(
@@ -51,12 +48,21 @@ def setup_parser(subparser):
help='Show full dependency DAG of installed packages')
subparser.add_argument(
+ '-l', '--long', action='store_true', dest='long',
+ help='Show dependency hashes as well as versions.')
+
+ subparser.add_argument(
'query_specs', nargs=argparse.REMAINDER,
help='optional specs to filter results')
+def gray_hash(spec):
+ return colorize('@K{[%s]}' % spec.dag_hash(7))
+
+
def display_specs(specs, **kwargs):
mode = kwargs.get('mode', 'short')
+ hashes = kwargs.get('long', False)
# Make a dict with specs keyed by architecture and compiler.
index = index_by(specs, ('architecture', 'compiler'))
@@ -85,13 +91,20 @@ def display_specs(specs, **kwargs):
elif mode == 'deps':
for spec in specs:
- print spec.tree(indent=4, format='$_$@$+$#', color=True),
-
- elif mode in ('short', 'long'):
- fmt = '$-_$@$+'
- if mode == 'long':
- fmt += '$#'
- colify(s.format(fmt, color=True) for s in specs)
+ print spec.tree(
+ format='$_$@$+',
+ color=True,
+ indent=4,
+ prefix=(lambda s: gray_hash(s)) if hashes else None)
+
+ elif mode == 'short':
+ def fmt(s):
+ string = ""
+ if hashes:
+ string += gray_hash(s) + ' '
+ string += s.format('$-_$@$+', color=True)
+ return string
+ colify(fmt(s) for s in specs)
else:
raise ValueError(
@@ -125,5 +138,4 @@ def find(parser, args):
if sys.stdout.isatty():
tty.msg("%d installed packages." % len(specs))
- display_specs(specs, mode=args.mode)
-
+ display_specs(specs, mode=args.mode, long=args.long)
diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py
index 21e36de14d..5f34a33ac1 100644
--- a/lib/spack/spack/spec.py
+++ b/lib/spack/spack/spec.py
@@ -120,6 +120,7 @@ architecture_color = '@m'
enabled_variant_color = '@B'
disabled_variant_color = '@r'
dependency_color = '@.'
+hash_color = '@K'
"""This map determines the coloring of specs when using color output.
We make the fields different colors to enhance readability.
@@ -129,7 +130,8 @@ color_formats = {'%' : compiler_color,
'=' : architecture_color,
'+' : enabled_variant_color,
'~' : disabled_variant_color,
- '^' : dependency_color }
+ '^' : dependency_color,
+ '#' : hash_color }
"""Regex used for splitting by spec field separators."""
_separators = '[%s]' % ''.join(color_formats.keys())
@@ -1296,7 +1298,7 @@ class Spec(object):
$%@ Compiler & compiler version
$+ Options
$= Architecture
- $# Dependencies' 8-char sha1 prefix
+ $# 7-char prefix of DAG hash
$$ $
Optionally you can provide a width, e.g. $20_ for a 20-wide name.
@@ -1352,8 +1354,7 @@ class Spec(object):
if self.architecture:
write(fmt % (c + str(self.architecture)), c)
elif c == '#':
- if self.dependencies:
- out.write(fmt % ('-' + self.dag_hash(8)))
+ out.write('-' + fmt % (self.dag_hash(7)))
elif c == '$':
if fmt != '':
raise ValueError("Can't use format width with $$.")
@@ -1399,12 +1400,15 @@ class Spec(object):
cover = kwargs.pop('cover', 'nodes')
indent = kwargs.pop('indent', 0)
fmt = kwargs.pop('format', '$_$@$%@$+$=')
+ prefix = kwargs.pop('prefix', None)
check_kwargs(kwargs, self.tree)
out = ""
cur_id = 0
ids = {}
for d, node in self.traverse(order='pre', cover=cover, depth=True):
+ if prefix is not None:
+ out += prefix(node)
out += " " * indent
if depth:
out += "%-4d" % d