From c5036e54aba6a2a7ddf9d6e5afe6603e6b37f6a5 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Sun, 22 Jan 2023 18:27:04 +0100 Subject: first draft Signed-off-by: Olivier Gayot --- app.py | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 app.py diff --git a/app.py b/app.py new file mode 100644 index 0000000..87c4898 --- /dev/null +++ b/app.py @@ -0,0 +1,123 @@ +import io +import json +import tarfile +import tempfile +from urllib.request import urlopen +import urllib.error + +import flask +from flask import Flask, jsonify +from launchpadlib.launchpad import Launchpad + +app = Flask(__name__) + + +@app.route("/", methods=["GET"]) +def index_root(): + tmpdir = tempfile.TemporaryDirectory() + + launchpad = Launchpad.login_anonymously("just testing", "production", tmpdir.name, version="devel") + ogayot = launchpad.people["ogayot"] + + runs = [] + + for ppa in ogayot.ppas: + series_set = set() + for source_pkg in ppa.getPublishedSources(): + series_set.add(source_pkg.distro_series.name) + + for series in series_set: + RELEASE = series + LPUSER = ogayot.name + PPA = ppa.name + + try: + runs.append(json.loads(urlopen(f"https://autopkgtest.ubuntu.com/results/autopkgtest-{RELEASE}-{LPUSER}-{PPA}/?format=json").read())) + except urllib.error.HTTPError: + pass + + return jsonify(runs) + +@app.route("/", methods=["GET"]) +def index_ppa(ppa_name): + tmpdir = tempfile.TemporaryDirectory() + + launchpad = Launchpad.login_anonymously("just testing", "production", tmpdir.name, version="devel") + ogayot = launchpad.people["ogayot"] + + runs = [] + + ppa = next(filter(lambda p: p.name == ppa_name, ogayot.ppas)) + series_set = set() + for source_pkg in ppa.getPublishedSources(): + series_set.add(source_pkg.distro_series.name) + + for series in series_set: + RELEASE = series + LPUSER = ogayot.name + PPA = ppa.name + + try: + runs.append(json.loads(urlopen(f"https://autopkgtest.ubuntu.com/results/autopkgtest-{RELEASE}-{LPUSER}-{PPA}/?format=json").read())) + except urllib.error.HTTPError: + pass + + return jsonify(runs) + +@app.route("/ogayot/bionic-proposed/unattended-upgrades") +def index_toto(): + RELEASE = "bionic" + LPUSER = "ogayot" + PPA = "bionic-proposed" + + autopkgtest_url_base = f"https://autopkgtest.ubuntu.com/results/autopkgtest-{RELEASE}-{LPUSER}-{PPA}" + data = json.loads(urlopen(f"{autopkgtest_url_base}?format=json").read()) + + # Use the prefix as index + runs = {} + + for info in data: + index, suffix = info["name"].rsplit("/", maxsplit=1) + if suffix != "result.tar": + continue + runs[index] = info + + headers = ("version", "triggers", "date", "duration", "requester", "result", "url_prefix") + package_results = [] + for idx, info in runs.items(): + date = " ".join(idx.split("/")[-1].split("_")[0:2]), + tar_stream = io.BytesIO(urlopen(f"{autopkgtest_url_base}/{info['name']}").read()) + file = tarfile.open(fileobj=tar_stream) + exitcode = int(file.extractfile("exitcode").read().decode().splitlines()[0]) + duration = int(file.extractfile("duration").read().decode().splitlines()[0]) + version = file.extractfile("testpkg-version").read().decode().splitlines()[0].split(" ")[-1] + requester = file.extractfile("requester").read().decode().splitlines()[0] + testinfo = json.loads(file.extractfile("testinfo.json").read().decode()) + for entry in testinfo["custom_environment"]: + key, value = entry.split("=", maxsplit=1) + if key == "ADT_TEST_TRIGGERS": + triggers = value + break + else: + triggers = "?" + + result = { + "version": version, + "triggers": triggers, + "date": " ".join(idx.split("/")[-1].split("_")[0:2]), + "duration": duration, + "requester": requester, + "result": exitcode, + "url_prefix": f"{autopkgtest_url_base}/{idx}", + } + package_results.append([result[h] for h in headers]) + + + return flask.render_template("browse-results.html", + package="unattended-upgrades", + release="bionic", + arch="amd64", + package_results=package_results, + title_suffix="ogayot bionic-proposed unattended-upgrades", + base_url="https://autopkgtest.ubuntu.com/", + ) -- cgit v1.2.3