Better hash output in find.
This commit is contained in:
parent
43e5465592
commit
b4a26c496c
@ -40,9 +40,6 @@
|
|||||||
|
|
||||||
def setup_parser(subparser):
|
def setup_parser(subparser):
|
||||||
format_group = subparser.add_mutually_exclusive_group()
|
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(
|
format_group.add_argument(
|
||||||
'-p', '--paths', action='store_const', dest='mode', const='paths',
|
'-p', '--paths', action='store_const', dest='mode', const='paths',
|
||||||
help='Show paths to package install directories')
|
help='Show paths to package install directories')
|
||||||
@ -50,13 +47,22 @@ def setup_parser(subparser):
|
|||||||
'-d', '--deps', action='store_const', dest='mode', const='deps',
|
'-d', '--deps', action='store_const', dest='mode', const='deps',
|
||||||
help='Show full dependency DAG of installed packages')
|
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(
|
subparser.add_argument(
|
||||||
'query_specs', nargs=argparse.REMAINDER,
|
'query_specs', nargs=argparse.REMAINDER,
|
||||||
help='optional specs to filter results')
|
help='optional specs to filter results')
|
||||||
|
|
||||||
|
|
||||||
|
def gray_hash(spec):
|
||||||
|
return colorize('@K{[%s]}' % spec.dag_hash(7))
|
||||||
|
|
||||||
|
|
||||||
def display_specs(specs, **kwargs):
|
def display_specs(specs, **kwargs):
|
||||||
mode = kwargs.get('mode', 'short')
|
mode = kwargs.get('mode', 'short')
|
||||||
|
hashes = kwargs.get('long', False)
|
||||||
|
|
||||||
# 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'))
|
||||||
@ -85,13 +91,20 @@ def display_specs(specs, **kwargs):
|
|||||||
|
|
||||||
elif mode == 'deps':
|
elif mode == 'deps':
|
||||||
for spec in specs:
|
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'):
|
elif mode == 'short':
|
||||||
fmt = '$-_$@$+'
|
def fmt(s):
|
||||||
if mode == 'long':
|
string = ""
|
||||||
fmt += '$#'
|
if hashes:
|
||||||
colify(s.format(fmt, color=True) for s in specs)
|
string += gray_hash(s) + ' '
|
||||||
|
string += s.format('$-_$@$+', color=True)
|
||||||
|
return string
|
||||||
|
colify(fmt(s) for s in specs)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
@ -125,5 +138,4 @@ def find(parser, args):
|
|||||||
|
|
||||||
if sys.stdout.isatty():
|
if sys.stdout.isatty():
|
||||||
tty.msg("%d installed packages." % len(specs))
|
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'
|
enabled_variant_color = '@B'
|
||||||
disabled_variant_color = '@r'
|
disabled_variant_color = '@r'
|
||||||
dependency_color = '@.'
|
dependency_color = '@.'
|
||||||
|
hash_color = '@K'
|
||||||
|
|
||||||
"""This map determines the coloring of specs when using color output.
|
"""This map determines the coloring of specs when using color output.
|
||||||
We make the fields different colors to enhance readability.
|
We make the fields different colors to enhance readability.
|
||||||
@ -129,7 +130,8 @@
|
|||||||
'=' : architecture_color,
|
'=' : architecture_color,
|
||||||
'+' : enabled_variant_color,
|
'+' : enabled_variant_color,
|
||||||
'~' : disabled_variant_color,
|
'~' : disabled_variant_color,
|
||||||
'^' : dependency_color }
|
'^' : dependency_color,
|
||||||
|
'#' : hash_color }
|
||||||
|
|
||||||
"""Regex used for splitting by spec field separators."""
|
"""Regex used for splitting by spec field separators."""
|
||||||
_separators = '[%s]' % ''.join(color_formats.keys())
|
_separators = '[%s]' % ''.join(color_formats.keys())
|
||||||
@ -1296,7 +1298,7 @@ def format(self, format_string='$_$@$%@$+$=', **kwargs):
|
|||||||
$%@ Compiler & compiler version
|
$%@ Compiler & compiler version
|
||||||
$+ Options
|
$+ Options
|
||||||
$= Architecture
|
$= 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.
|
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:
|
if self.architecture:
|
||||||
write(fmt % (c + str(self.architecture)), c)
|
write(fmt % (c + str(self.architecture)), c)
|
||||||
elif c == '#':
|
elif c == '#':
|
||||||
if self.dependencies:
|
out.write('-' + fmt % (self.dag_hash(7)))
|
||||||
out.write(fmt % ('-' + self.dag_hash(8)))
|
|
||||||
elif c == '$':
|
elif c == '$':
|
||||||
if fmt != '':
|
if fmt != '':
|
||||||
raise ValueError("Can't use format width with $$.")
|
raise ValueError("Can't use format width with $$.")
|
||||||
@ -1399,12 +1400,15 @@ def tree(self, **kwargs):
|
|||||||
cover = kwargs.pop('cover', 'nodes')
|
cover = kwargs.pop('cover', 'nodes')
|
||||||
indent = kwargs.pop('indent', 0)
|
indent = kwargs.pop('indent', 0)
|
||||||
fmt = kwargs.pop('format', '$_$@$%@$+$=')
|
fmt = kwargs.pop('format', '$_$@$%@$+$=')
|
||||||
|
prefix = kwargs.pop('prefix', None)
|
||||||
check_kwargs(kwargs, self.tree)
|
check_kwargs(kwargs, self.tree)
|
||||||
|
|
||||||
out = ""
|
out = ""
|
||||||
cur_id = 0
|
cur_id = 0
|
||||||
ids = {}
|
ids = {}
|
||||||
for d, node in self.traverse(order='pre', cover=cover, depth=True):
|
for d, node in self.traverse(order='pre', cover=cover, depth=True):
|
||||||
|
if prefix is not None:
|
||||||
|
out += prefix(node)
|
||||||
out += " " * indent
|
out += " " * indent
|
||||||
if depth:
|
if depth:
|
||||||
out += "%-4d" % d
|
out += "%-4d" % d
|
||||||
|
Loading…
Reference in New Issue
Block a user