From c1e0c1353c5efaccf3ed4628f22589ab6a133100 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Sun, 22 Jan 2023 19:53:18 +0100 Subject: add templates to browse Signed-off-by: Olivier Gayot --- app.py | 33 ++++++++++++++++++++++++++++----- templates/list-arches.html | 5 +++++ templates/list-packages.html | 5 +++++ templates/list-ppas.html | 5 +++++ templates/list-series.html | 5 +++++ 5 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 templates/list-arches.html create mode 100644 templates/list-packages.html create mode 100644 templates/list-ppas.html create mode 100644 templates/list-series.html diff --git a/app.py b/app.py index e6d84b9..f7257e5 100644 --- a/app.py +++ b/app.py @@ -1,4 +1,5 @@ import io +from html import escape import json import tarfile import tempfile @@ -15,6 +16,8 @@ tmpdir = tempfile.TemporaryDirectory() launchpad = Launchpad.login_anonymously("just testing", "production", tmpdir.name, version="devel") +use_json = False + @app.route("/") def index_root(): return redirect("/ogayot", code=302) @@ -24,7 +27,12 @@ def index_root(): def index_lpuser(LPUSER): lpuser = launchpad.people[LPUSER] - return jsonify([ppa.name for ppa in lpuser.ppas]) + ppas = [ppa.name for ppa in lpuser.ppas] + if use_json: + return jsonify(ppas) + else: + return flask.render_template("list-ppas.html", ppas=ppas, + base_url=flask.request.base_url) @app.route("//") @@ -33,7 +41,12 @@ def index_ppa(LPUSER, PPA): ppa = next(filter(lambda p: p.name == PPA, lpuser.ppas)) - return jsonify(list(set([pkg.source_package_name for pkg in ppa.getPublishedSources()]))) + packages = list(set([pkg.source_package_name for pkg in ppa.getPublishedSources()])) + if use_json: + return jsonify(packages) + else: + return flask.render_template("list-packages.html", packages=packages, + base_url=flask.request.base_url) @app.route("///") @@ -49,7 +62,12 @@ def index_package(LPUSER, PPA, PACKAGE): continue series_set.add(source_pkg.distro_series.name) - return jsonify(list(series_set)) + series = list(series_set) + if use_json: + return jsonify(series) + else: + return flask.render_template("list-series.html", series=series, + base_url=flask.request.base_url) @app.route("////") @@ -58,13 +76,18 @@ def index_release(LPUSER, PPA, PACKAGE, RELEASE): try: data = json.loads(urlopen(f"https://autopkgtest.ubuntu.com/results/autopkgtest-{RELEASE}-{LPUSER}-{PPA}/?format=json").read()) except urllib.error.HTTPError: - return jsonify([]) + data = [] arches_set = set() for section in data: arches_set.add(section["name"].split("/")[1]) - return jsonify(list(arches_set)) + arches = list(arches_set) + if use_json: + return jsonify(arches) + else: + return flask.render_template("list-arches.html", arches=arches, + base_url=flask.request.base_url) @app.route("/////") diff --git a/templates/list-arches.html b/templates/list-arches.html new file mode 100644 index 0000000..d5f10fe --- /dev/null +++ b/templates/list-arches.html @@ -0,0 +1,5 @@ +
    + {% for arch in arches %} +
  • {{arch}}
  • + {% endfor %} +
diff --git a/templates/list-packages.html b/templates/list-packages.html new file mode 100644 index 0000000..dc2c8b9 --- /dev/null +++ b/templates/list-packages.html @@ -0,0 +1,5 @@ +
    + {% for pkg in packages %} +
  • {{pkg}}
  • + {% endfor %} +
diff --git a/templates/list-ppas.html b/templates/list-ppas.html new file mode 100644 index 0000000..b89cf31 --- /dev/null +++ b/templates/list-ppas.html @@ -0,0 +1,5 @@ +
    + {% for ppa in ppas %} +
  • {{ppa}}
  • + {% endfor %} +
diff --git a/templates/list-series.html b/templates/list-series.html new file mode 100644 index 0000000..2948ae8 --- /dev/null +++ b/templates/list-series.html @@ -0,0 +1,5 @@ +
    + {% for release in series %} +
  • {{release}}
  • + {% endfor %} +
-- cgit v1.2.3