Better hash output in find.
This commit is contained in:
parent
43e5465592
commit
b4a26c496c
@ -40,9 +40,6 @@
|
||||
|
||||
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')
|
||||
@ -50,13 +47,22 @@ def setup_parser(subparser):
|
||||
'-d', '--deps', action='store_const', dest='mode', const='deps',
|
||||
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),
|
||||
print spec.tree(
|
||||
format='$_$@$+',
|
||||
color=True,
|
||||
indent=4,
|
||||
prefix=(lambda s: gray_hash(s)) if hashes else None)
|
||||
|
||||
elif mode in ('short', 'long'):
|
||||
fmt = '$-_$@$+'
|
||||
if mode == 'long':
|
||||
fmt += '$#'
|
||||
colify(s.format(fmt, color=True) for s in specs)
|
||||
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)
|
||||
|
@ -120,6 +120,7 @@
|
||||
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 @@
|
||||
'=' : 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 @@ def format(self, format_string='$_$@$%@$+$=', **kwargs):
|
||||
$%@ 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 @@ def write(s, c):
|
||||
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 @@ def tree(self, **kwargs):
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user