port-compare/port_stats/reports.py
Ivan A. Melnikov e0b48e098d update_days: Ignore fresh packages that were never rebuild
Threre was a time when this was important enough
for sisyphus_mipsel, but now, especially for p9_mipsel,
this is just noise.
2020-09-18 13:42:13 +04:00

127 lines
4.2 KiB
Python

import logging
from port_stats import colorize
from port_stats import lists
from port_stats import tasks
from port_stats import utils
LOG = logging.getLogger(__name__)
def percent(small, big):
perc = (100.0 * small) / big
return "%6s (%6.2f%% of %s)" % (small, perc, big)
def text_totals(keys, data, legend=(), total=None):
result = []
for key in keys:
if total:
message = "%10s:%-24s" % (key, percent(data.get(key), total))
else:
message = '%10s:%6s' % (key, data.get(key))
if key in legend:
message += ' // %s' % legend[key]
result.append(message)
if total:
result.append('%10s:%6s' % ('[TOTAL]', total))
return '\n'.join(result)
COLORS_EX = tuple(colorize.COLORS) + ('[RECENT]', '[PENDING]')
def color_stats(by_color, names=None):
if names:
data = dict((color, sum(1 for p in by_color[color] if p[0] in names))
for color in colorize.COLORS)
else:
data = dict((color, len(by_color[color]))
for color in colorize.COLORS)
data['[PENDING]'] = data.get('ORANGE', 0) + data.get('YELLOW', 0)
data['[RECENT]'] = data.get('GREEN', 0) + data.get('SLATE', 0)
return data
def color_totals(by_color, names=None, total=None, summary=False):
data = color_stats(by_color, names)
if summary:
keys = COLORS_EX
legend = dict(colorize.LEGEND)
legend['[RECENT]'] = 'recent enough'
legend['[PENDING]'] = 'updates are pending'
else:
keys = colorize.COLORS
legend = colorize.LEGEND
return text_totals(keys, data, legend, total)
def package_one_line(name, by_name, package_tasks, separator='\t'):
color, bp, np = by_name[name]
tasks_str = tasks.format_tasks_short(package_tasks.get(name))
return '\t'.join((color, name, lists.format_evr(bp),
lists.format_evr(np), tasks_str))
def format_colored_task(info, by_name):
return tasks.format_task(
info,
extra_info=colorize.package_colorizer(by_name, 'NONE'))
def update_days(by_name, package_tasks, update_times, now):
java = []
recent = []
old = []
for name in by_name:
color, bp, np = by_name[name]
if color == 'RED' or color == 'NONE':
continue
last_update = update_times.get(name, 0)
infos = package_tasks.get(name, ())
if not infos and color in ['GREEN', 'SLATE']:
# fresh package that was never rebuild
continue
# for outdated packages, check for newer versions
# for SLATE packages, check for base repo version rebuilds
rebuild_nevr = np if color in ('ORANGE', 'YELLOW', 'EXTRA') else bp
try:
first_pending = min(
info['task_ctime'] for info in infos
if tasks.task_is_updating(info, rebuild_nevr, last_update))
except ValueError:
# if package was never updated, set update date to 2018-01-01
first_pending = 1514750400
LOG.debug('name=%s, first_pending=%s, last_update=%s',
name, first_pending, last_update)
if first_pending < last_update:
continue
about = package_one_line(name, by_name, package_tasks)
days_pendig = utils.days_from(first_pending, now)
days_updated = (utils.days_from(last_update, now)
if last_update else 99999)
ev = (days_pendig, days_updated, about)
if days_pendig <= 3:
recent.append(ev)
elif 'jpp' in about:
java.append(ev)
else:
old.append(ev)
total = len(recent) + len(old) + len(java)
return ('days pending // days since update // color // name'
+ ' // latest version // current version // tasks\n'
+ '\n\nTOTALLY PENDING: %s' % total
+ '\n\nRECENT (%s) // not yet old\n' % len(recent)
+ '\n'.join('%5s %5s\t%s' % x for x in sorted(recent))
+ '\n\nOLD (%s) // update pending for 4+ days\n' % len(old)
+ '\n'.join('%5s %5s\t%s' % x for x in sorted(old))
+ '\n\nOLD JAVA (%s) // has its own category\n' % len(java)
+ '\n'.join('%5s %5s\t%s' % x for x in sorted(java)))