From 39dd3cc2291d2cf526fc21389f595bfa18e92205 Mon Sep 17 00:00:00 2001 From: Mattia Rizzolo Date: Sat, 10 Jan 2015 02:59:57 +0100 Subject: reproducible: add reproducible_html_packages.py --- bin/reproducible_html_packages.py | 155 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100755 bin/reproducible_html_packages.py diff --git a/bin/reproducible_html_packages.py b/bin/reproducible_html_packages.py new file mode 100755 index 00000000..75b786f5 --- /dev/null +++ b/bin/reproducible_html_packages.py @@ -0,0 +1,155 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + +# clean-notes: sort and clean the notes stored in notes.git +# Copyright © 2015 Mattia Rizzolo +# Licensed under GPL-2+ +# +# Depends: python3 + + +from reproducible_common import * + +html_package_page = Template((tab*2).join((""" + + + + + +
+ $package $version + + $status + + at $build_time: +$links + rbuild ($rbuild_size) + PTS + BTS + sources + debian/rules + + + reproducible builds + +
+""" % REPRODUCIBLE_URL ).splitlines(True))) + + +def sizeof_fmt(num): + for unit in ['B','KB','MB','GB','TB','PB','EB','ZB']: + if abs(num) < 1024.0: + return str(int(round(float("%3f" % num), 0))) + "%s" % (unit) + num /= 1024.0 + return str(int(round(float("%f" % num), 0))) + "%s" % ('Yi') + + +def check_package_status(package): + """ + This returns a tuple containing status, version and build_date of the last + version of the package built by jenkins CI + """ + try: + query = 'SELECT status,version,build_date ' + \ + 'FROM source_packages ' + \ + 'WHERE name="%s"' % package + result = query_db(query)[0] + except IndexError: + log.critical('The query produces no results. The query: ' + query) + raise + status = str(result[0]) + version = str(result[1]) + build_date = str(result[2]) + return (status, version, build_date) + +def gen_extra_links(package, version): + notes = NOTES_PATH + '/' + package + '_note.html' + buildinfo = BUILDINFO_PATH + '/' + package + '_' + version + '_amd64.buildinfo' + dbd = DBD_PATH + '/' + package + '_' + version + '.debbindiff.html' + + links = '' + default_view = False + # check whether there are notes available for this package + if os.access(notes, os.R_OK): + url = NOTES_URI + '/' + package + '_note.html' + links += 'notes\n' + default_view = url + else: + log.debug('notes not detected at ' + notes) + if os.access(dbd, os.R_OK): + url = DBD_URI + '/' + package + '_' + version + '.debbindiff.html' + links += 'debbindiff\n' + if not default_view: + default_view = url + else: + log.debug('debbindiff not detetected at ' + dbd) + if os.access(buildinfo, os.R_OK): + url = BUILDINFO_URI + '/' + package + '_' + version + '_amd64.buildinfo' + links += 'buildinfo\n' + if not default_view: + default_view = url + else: + log.debug('buildinfo not detected at ' + buildinfo) + return (links, default_view) + + +def process_packages(packages): + """ + generate the /rb-pkg/package.html page + packages should be a list + """ + total = len(packages) + log.info('Generating the pages of ' + str(total) + ' package(s)') + for pkg in sorted(packages): + pkg = str(pkg) + status, version, build_date = check_package_status(pkg) + log.info('Generating the page of ' + pkg + ' ' + version + + ' builded at ' + build_date) + + rbuild = RBUILD_PATH + '/' + pkg + '_' + version + '.rbuild.log' + links, default_view = gen_extra_links(pkg, version) + + if not default_view: # this is only possible only if there are no notes, + # debbindiff or buildinfo files + default_view = RBUILD_URI + '/' + pkg + '_' + version + '.rbuild.log' + try: + log_size = os.stat(rbuild).st_size + except FileNotFoundError: + log.warning('The package ' + pkg + + ' did not produce any buildlog! Check ' + rbuild) + log_size = 0 + pass + status, icon = join_status_icon(status, pkg, version) + html = html_package_page.substitute(package=pkg, + status=status, + version=version, + build_time=build_date, + icon=icon, + links=links, + rbuild_size=sizeof_fmt(log_size), + default_view=default_view) + destfile = RB_PKG_PATH + '/' + pkg + '.html' + desturl = REPRODUCIBLE_URL + RB_PKG_URI + '/' + pkg + '.html' + title = pkg + ' reproducible build results' + write_html_page(title=title, body=html, destfile=destfile, + noheader=True, nofooter=True, noendpage=True) + log.info("Package page generated at " + desturl) + purge_old_pages() # housekeep is always good + + +def purge_old_pages(): + presents = sorted(os.listdir(RB_PKG_PATH)) + for page in presents: + pkg = page.rsplit('.', 1)[0] + log.debug('Checking if ' + page + ' (from ' + pkg + ') is still needed') + query = 'SELECT name FROM source_packages WHERE name="%s"' % pkg + result = query_db(query) + if not result: # actually, the query produces no results + log.info('There is no package named ' + pkg + ' in the database.' + + ' Removing old page.') + os.remove(RB_PKG_PATH + '/' + page) -- cgit v1.2.3-54-g00ecf