Add next_tasks to daily report

This commit is contained in:
Ivan A. Melnikov 2018-08-14 14:13:21 +04:00
parent 08af75a9b9
commit f88c01316b
3 changed files with 52 additions and 31 deletions

View File

@ -60,8 +60,14 @@ def _unmets(repo, out_file):
os.unlink(fname)
def _percent(small, big):
perc = (100.0 * small) / big
return "%s (%.2f%% of %s)" % (small, perc, big)
def daily_report(out_dir, what, repos, all_tasks):
LOG.info("Writing daily report for %s", what['name'])
now = datetime.datetime.utcnow()
base_name = what['base']
new_name = what['new']
@ -76,21 +82,30 @@ def daily_report(out_dir, what, repos, all_tasks):
base = repos[base_name]
new = repos[new_name]
base_size = len(base)
new_size = len(new)
LOG.info("%s: %s tasks; base repo size is %s; repo size is %s",
what['name'], len(task_list), len(base), len(new))
what['name'], len(task_list), base_size, new_size)
by_name, by_color = colorize.colorize(base, new)
color_stats = dict((color, len(by_color[color]))
for color in colorize.COLORS)
old = color_stats.get('ORANGE', 0) + color_stats.get('YELLOW', 0)
fresh = color_stats.get('GREEN', 0) + color_stats.get('SLATE', 0)
# All the stats for message body
with open(os.path.join(out_dir, 'stats.txt'), 'w') as stats:
print("Summary report for ", what['name'], file=stats)
now = datetime.datetime.utcnow()
print("Date:", now.isoformat(' '), 'UTC', file=stats)
print(base_name, "SRPMs:", len(base), file=stats)
print(new_name, "SRPMs:", len(new), file=stats)
print("Tasks loaded:", len(task_list), file=stats)
next_tasks = reports.next_tasks(task_list, by_name, new_name)
state_stats['[UPDATES]'] = len(next_tasks)
stats_path = os.path.join(out_dir, 'stats.txt')
LOG.info("Writing stats to %s", stats_path)
with open(stats_path, 'w') as stats:
print("Summary report for", what['name'],
"at", now.isoformat(' '), 'UTC', file=stats)
print(base_name, "SRPMs:", base_size, file=stats)
print(new_name, "SRPMs:", _percent(new_size, base_size), file=stats)
print(" recent enough:", _percent(fresh, new_size), file=stats)
print(" update pending:", _percent(old, new_size), file=stats)
print("\nPackage statistics:", file=stats)
reports.text_totals(colorize.COLORS, color_stats,
@ -110,6 +125,10 @@ def daily_report(out_dir, what, repos, all_tasks):
with open(os.path.join(out_dir, 'colorized.tsv'), 'w') as out:
reports.color_packages(by_name, package_tasks, out)
# next tasks
with open(os.path.join(out_dir, 'next_tasks.txt'), 'w') as out:
for t in next_tasks:
print("\n%s" % t, file=out)
if __name__ == '__main__':
sys.exit(main(*sys.argv[1:]))

View File

@ -163,27 +163,9 @@ def ti(num, to=print):
to(_ti_str(get_task(num, TASKS)))
def _filtered_tasks(*preds):
return sorted((t for t in TASKS if all(p(t) for p in preds)),
key=lambda x: utils.maybe_int(x['taskid']))
def _format_ti(info_list):
return '\n\n'.join(_ti_str(info) for info in info_list)
def _task_colors(info):
colors = (colorize.package_color(p, BY_NAME)
for p in tasks.task_packages(info))
return frozenset(c for c in colors if c)
def next_tasks(colors=frozenset(['ORANGE', 'YELLOW', 'EXTRA']), to=pager):
tasks = _filtered_tasks(lambda t: t['state'] != 'DONE',
lambda t: t['repo'] == CURRENT['new'],
lambda t: _task_colors(t) & colors,
lambda t: t['owner'].startswith('recycler'))
to("%s tasks\n\n%s" % (len(tasks), _format_ti(tasks)))
def next_tasks(to=pager):
tasks = reports.next_tasks(TASKS, BY_NAME, CURRENT['new'])
to("%s tasks\n\n%s" % (len(tasks), '\n\n'.join(tasks)))
def fti(num, to=print):

View File

@ -36,3 +36,23 @@ def color_packages(by_name, package_tasks, out_file):
for name in sorted(by_name):
print(package_one_line(name, by_name, package_tasks), file=out_file)
def _task_colors(info, by_name):
colors = (colorize.package_color(p, by_name)
for p in tasks.task_packages(info))
return frozenset(c for c in colors if c)
def next_tasks(task_list, by_name, repo):
def _colorize(p):
return colorize.package_color(p, by_name) or 'NONE'
colors=frozenset(['ORANGE', 'YELLOW', 'EXTRA'])
infos = sorted((t for t in task_list
if t['state'] != 'DONE'
and t['repo'] == repo
and _task_colors(t, by_name) & colors
and t['owner'].startswith('recycler')),
key=lambda x: utils.maybe_int(x['taskid']))
return [tasks.format_task(t, extra_info=_colorize) for t in infos]