Skip to content

Commit

Permalink
pmerge: color code display_failure output.
Browse files Browse the repository at this point in the history
green == normal
yellow == unsolved
red == failure point.

It's not perfect, but it does make it easier
for the eye to zero in on the relevant data.

Closes: #329
  • Loading branch information
ferringb authored and mgorny committed Sep 27, 2021
1 parent f9e04e4 commit f5fa26b
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/pkgcore/scripts/pmerge.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,21 +366,35 @@ def do_unmerge(options, out, err, vdb, matches, world_set, repo_obs):
out.write(f"finished; removed {len(matches)} packages")


def display_failures(out, sequence, first_level=True, debug=False):
def display_failures(out, sequence, first_level=True, debug=False, _color_index=None):
"""when resolution fails, display a nicely formatted message"""

sequence = iter(sequence)
frame = next(sequence)

def set_color(color):
out.first_prefix[_color_index] = out.fg(color)

if first_level:
# _color_index is an encapsulation failure; we're modifying the formatters
# prefix directly; that's very much a hack. Don't rely on it beyond in
# this function.
_color_index = len(out.first_prefix)
# pops below need to exactly match.
out.first_prefix.extend((out.fg("red"), "!!! ", out.reset))
out.first_prefix.extend((out.fg("green"), "!!! ", out.reset))
else:
assert _color_index is not None
set_color("green")

out.write(f"request {frame.atom}, mode {frame.mode}")
for pkg, steps in sequence:
set_color("yellow")
out.write(f"trying {pkg.cpvstr}")
out.first_prefix.append(" ")
for step in steps:
set_color("red")
if isinstance(step, list):
display_failures(out, step, False, debug=debug)
display_failures(out, step, False, debug=debug, _color_index=_color_index)
elif step[0] == 'reduce':
out.write("removing choices involving %s" %
', '.join(str(x) for x in step[1]))
Expand All @@ -396,6 +410,7 @@ def display_failures(out, sequence, first_level=True, debug=False):
out.write("failed due to %s" % (step[3],))
elif step[0] == "debug":
if debug:
set_color("yellow")
out.write(step[1])
else:
out.write(step)
Expand Down

0 comments on commit f5fa26b

Please sign in to comment.