interactive: Annotate ti and *spi with annotations

This commit is contained in:
Ivan A. Melnikov 2024-11-28 18:27:57 +04:00
parent 9d2e14f5dc
commit d98fc78de6
2 changed files with 23 additions and 9 deletions

View File

@ -131,7 +131,7 @@ def use(repo=None):
if annotation_file:
LOG.info("Loading annotations from %s", annotation_file)
with open(annotation_file, "r") as f:
ANNOTATES = dict(line.split('\t', 1) for line in f)
ANNOTATES = dict(line.strip().split('\t', 1) for line in f)
LOG.info("DONE")
@ -166,7 +166,7 @@ def update_days(to=pager):
def _spi_by_predicate(pred, colors):
colors = colors or colorize.COLORS
return '\n'.join(
reports.package_one_line(name, BY_NAME, PACKAGE_TASKS)
reports.package_one_line(name, BY_NAME, PACKAGE_TASKS, ANNOTATES)
for name in sorted(BY_NAME)
if pred(name) and BY_NAME[name][0] in colors)
@ -190,12 +190,20 @@ def list_spi(pkgs, colors=None, to=print):
to(lines)
def _colorizer():
return colorize.package_colorizer(BY_NAME, 'NONE')
def _annotator():
clr = colorize.package_colorizer(BY_NAME, 'NONE')
def _the_annotator(name):
ann = ANNOTATES.get(name)
if (ann):
return clr(name) + ' ' + ann
else:
return clr(name)
return _the_annotator
def ti(num, to=print):
to(tasks.format_task(get_task(num, TASKS), _colorizer()))
to(tasks.format_task(get_task(num, TASKS), _annotator()))
def display_tasks(infos=None, num=None, min_id=None, sort=None,
@ -205,7 +213,7 @@ def display_tasks(infos=None, num=None, min_id=None, sort=None,
infos = (t for t in infos if t['taskid'] >= min_id)
if sort is not None:
infos = sorted(infos, key=lambda t: t[sort])
czr = _colorizer()
czr = _annotator()
infos = (tasks.format_task(t, czr) for t in infos)
if include:
pi = re.compile(include)
@ -243,7 +251,7 @@ def _fresh_subtasks(info):
def fresh(num, color=True, to=print):
subtasks = _fresh_subtasks(get_task(num, TASKS))
if subtasks:
clr = _colorizer() if color else None
clr = _annotator() if color else None
items = sorted((int(k), tasks.format_subtask(s, clr))
for k, s in utils.items(subtasks))
to('\n'.join('%6d %s' % item for item in items))
@ -306,7 +314,7 @@ def inapt_reporter():
d = inapt.DependencyInfo.load(CONFIG['repos'][CURRENT['base']])
def _reporter(name, to=pager):
to(d.recursive_srpm_report(name, _colorizer()))
to(d.recursive_srpm_report(name, _annotator()))
return _reporter

View File

@ -57,9 +57,15 @@ def color_totals(by_color, names=None, total=None, summary=False):
return text_totals(keys, data, legend, total)
def package_one_line(name, by_name, package_tasks, separator='\t'):
def package_one_line(name, by_name, package_tasks,
annotations=None, separator='\t'):
color, bp, np = by_name[name]
tasks_str = tasks.format_tasks_short(package_tasks.get(name))
if annotations is not None:
ann = annotations.get(name, '')
annot_str = '[%s]' % ann.replace(separator, ' ')
return '\t'.join((color, name, lists.format_evr(bp),
lists.format_evr(np), annot_str, tasks_str))
return '\t'.join((color, name, lists.format_evr(bp),
lists.format_evr(np), tasks_str))