diff options
-rw-r--r-- | app.py | 81 |
1 files changed, 49 insertions, 32 deletions
@@ -6,63 +6,80 @@ from urllib.request import urlopen import urllib.error import flask -from flask import Flask, jsonify +from flask import Flask, jsonify, redirect from launchpadlib.launchpad import Launchpad app = Flask(__name__) +tmpdir = tempfile.TemporaryDirectory() + +launchpad = Launchpad.login_anonymously("just testing", "production", tmpdir.name, version="devel") @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) + return redirect("/ogayot", code=302) - 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 +@app.route("/<LPUSER>", methods=["GET"]) +def index_lpuser(LPUSER): + lpuser = launchpad.people[LPUSER] - return jsonify(runs) + return jsonify([ppa.name for ppa in lpuser.ppas]) -@app.route("/<ppa_name>", 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"] +@app.route("/<LPUSER>/<PPA>", methods=["GET"]) +def index_ppa(LPUSER, PPA): + lpuser = launchpad.people[LPUSER] runs = [] - ppa = next(filter(lambda p: p.name == ppa_name, ogayot.ppas)) + ppa = next(filter(lambda p: p.name == PPA, lpuser.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())) + urlopen(f"https://autopkgtest.ubuntu.com/results/autopkgtest-{RELEASE}-{LPUSER}-{PPA}/?format=json").read() except urllib.error.HTTPError: - pass + continue + + return jsonify(list(set([pkg.source_package_name for pkg in ppa.getPublishedSources()]))) + + +@app.route("/<LPUSER>/<PPA>/<PACKAGE>", methods=["GET"]) +def index_package(LPUSER, PPA, PACKAGE): + lpuser = launchpad.people[LPUSER] + + runs = [] + + ppa = next(filter(lambda p: p.name == PPA, lpuser.ppas)) + series_set = set() + for source_pkg in ppa.getPublishedSources(): + if source_pkg.source_package_name != PACKAGE: + continue + series_set.add(source_pkg.distro_series.name) + + return jsonify(list(series_set)) + + +@app.route("/<LPUSER>/<PPA>/<PACKAGE>/<RELEASE>") +def index_release(LPUSER, PPA, PACKAGE, RELEASE): + autopkgtest_url_base = f"https://autopkgtest.ubuntu.com/results/autopkgtest-{RELEASE}-{LPUSER}-{PPA}" + data = json.loads(urlopen(f"{autopkgtest_url_base}?format=json").read()) + try: + data = json.loads(urlopen(f"https://autopkgtest.ubuntu.com/results/autopkgtest-{RELEASE}-{LPUSER}-{PPA}/?format=json").read()) + except urllib.error.HTTPError: + return jsonify([]) + + arches_set = set() + for section in data: + arches_set.add(section["name"].split("/")[1]) + + return jsonify(list(arches_set)) - return jsonify(runs) @app.route("/<LPUSER>/<PPA>/<PACKAGE>/<RELEASE>/<ARCH>") def index_results(LPUSER, PPA, PACKAGE, RELEASE, ARCH): |