#!/usr/bin/python3
# -*- coding: utf-8 -*-
#
# Copyright © 2015 Holger Levsen
# based on ~jenkins.d.n:~mattia/status.sh by Mattia Rizzolo
# Licensed under GPL-2
#
# Depends: python3
#
from reproducible_common import *
from reproducible_html_indexes import build_leading_text_section
def convert_into_hms_string(duration):
if not duration:
duration = "None"
else:
hours = int(duration/3600)
minutes = int((duration-(hours*3600))/60)
seconds = int(duration-(hours*3600)-(minutes*60))
duration = ''
if hours > 0:
duration = str(hours)+'h ' + str(minutes)+'m ' + str(seconds) + 's'
elif minutes > 0:
duration = str(minutes)+'m ' + str(seconds) + 's'
else:
duration = str(seconds)+'s'
return duration
def generate_schedule(arch):
""" the schedule pages are very different than others index pages """
log.info('Building the schedule index page for ' + arch + '...')
title = 'Packages currently scheduled on ' + arch + ' for testing for build reproducibility'
query = 'SELECT sch.date_scheduled, s.suite, s.architecture, s.name, ' + \
'r.status, r.build_duration ' + \
'FROM schedule AS sch JOIN sources AS s ON sch.package_id=s.id LEFT JOIN results AS r ON s.id=r.package_id ' + \
'WHERE sch.date_build_started = "" AND s.architecture="{arch}" ORDER BY sch.date_scheduled'
text = Template('$tot packages are currently scheduled for testing on $arch:')
html = ''
rows = query_db(query.format(arch=arch))
html += build_leading_text_section({'text': text}, rows, defaultsuite, arch)
html += generate_live_status_table(arch)
html += '\n' + tab
html += '# | scheduled at | suite | '
html += 'arch | source package | previous build status | previous build duration |
\n'
bugs = get_bugs()
for row in rows:
# 0: date_scheduled, 1: suite, 2: arch, 3: pkg name 4: previous status 5: previous build duration
pkg = row[3]
duration = convert_into_hms_string(row[5])
html += tab + ' | ' + row[0] + ' | '
html += '' + row[1] + ' | ' + row[2] + ' | '
html += link_package(pkg, row[1], row[2], bugs)
html += ' | '+str(row[4])+' | '+duration+' |
\n'
html += '
\n'
destfile = BASE + '/index_' + arch + '_scheduled.html'
desturl = REPRODUCIBLE_URL + '/index_' + arch + '_scheduled.html'
write_html_page(title=title, body=html, destfile=destfile, arch=arch, style_note=True, refresh_every=60)
log.info("Page generated at " + desturl)
def generate_live_status_table(arch):
query = 'SELECT s.id, s.suite, s.architecture, s.name, s.version, ' + \
'p.date_build_started, r.status, r.build_duration, p.builder ' + \
'FROM sources AS s JOIN schedule AS p ON p.package_id=s.id LEFT JOIN results AS r ON s.id=r.package_id ' + \
'WHERE p.date_build_started != "" AND s.architecture="{arch}" ' + \
'ORDER BY p.date_build_started DESC'
html = ''
rows = query_db(query.format(arch=arch))
html += '\n' + tab
html += '# | src pkg id | suite | arch | '
html += 'source package | version | '
html += 'build started | previous build status | '
html += 'previous build duration | builder job | '
html += '
\n'
counter = 0
for row in rows:
counter += 1
# the numbers 13 and 7 should really be derived from /var/lib/jenkins/jobs/reproducible_builder_${arch}_* instead of being hard-coded here...
if ( arch == 'amd64' and counter == 13 ) or ( arch == 'armhf' and counter == 7 ):
html += 'There are more builds marked as currently building in the database than there are ' + arch + ' build jobs. This does not compute. Please cleanup and please automate cleanup. |
'
suite = row[1]
arch = row[2]
pkg = row[3]
duration = convert_into_hms_string(row[7])
html += tab + ' | ' + str(row[0]) + ' | '
html += '' + suite + ' | ' + arch + ' | '
html += '' + link_package(pkg, suite, arch) + ' | '
html += '' + str(row[4]) + ' | ' + str(row[5]) + ' | '
html += '' + str(row[6]) + ' | ' + duration + ' | '
html += '' + str(row[8]) + ' | '
html += '
\n'
html += '
\n'
return html
if __name__ == '__main__':
for arch in ARCHS:
generate_schedule(arch)