From 4fd1e5d7bb8b14b820c3cb4bad78785c9f002d09 Mon Sep 17 00:00:00 2001 From: Angelo D <43831545+AngeloD2022@users.noreply.github.com> Date: Wed, 29 Nov 2023 17:55:43 -0500 Subject: [PATCH 1/4] Created an HTML table-based "package releases" view. --- inspector/main.py | 14 +++++----- inspector/static/style.css | 10 +++++++ inspector/templates/releases.html | 45 +++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 inspector/templates/releases.html diff --git a/inspector/main.py b/inspector/main.py index a28d71e..826c691 100755 --- a/inspector/main.py +++ b/inspector/main.py @@ -67,13 +67,15 @@ def versions(project_name): if resp.status_code != 200: return redirect(pypi_project_url, 307) - version_urls = [ - "." + "/" + str(version) - for version in sorted(resp.json()["releases"].keys(), key=parse, reverse=True) - ] + releases = resp.json()["releases"] + sorted_releases = { + version: releases[version] + for version in sorted(releases.keys(), key=parse, reverse=True) + } + return render_template( - "links.html", - links=version_urls, + "releases.html", + releases=sorted_releases, h2=project_name, h2_link=f"/project/{project_name}", h2_paren="View this project on PyPI", diff --git a/inspector/static/style.css b/inspector/static/style.css index 1fd7dad..9d47c87 100644 --- a/inspector/static/style.css +++ b/inspector/static/style.css @@ -14,3 +14,13 @@ display: block; color: red; } + +table, th, td { + border: 1px solid black; + border-collapse: collapse; + padding: 4px; +} + +.no-entries { + color: grey; +} diff --git a/inspector/templates/releases.html b/inspector/templates/releases.html new file mode 100644 index 0000000..fa90ba5 --- /dev/null +++ b/inspector/templates/releases.html @@ -0,0 +1,45 @@ +{% extends 'base.html' %} + +{% block head %} + +{% endblock %} + +{% block body %} +{% if releases|length != 1 %} +

Retrieved {{ releases|length }} versions.

+{% else %} +

Retrieved 1 version.

+{% endif %} + + ++ + + + + + + + + + + +{% for key, value in releases.items() %} + + {% if value|length > 0 %} + + + + {% else %} + + + + {% endif %} + +{% endfor %} + + + +
VersionUpload TimestampArtifacts
{{ key }}{{ value[0]['upload_time'] }}{{ value|length }}{{ key }}Not AvailableNot Available
+ +{% endblock %} From a662208298e72ca2b40e3bb8ecddc7541c3f9d48 Mon Sep 17 00:00:00 2001 From: Angelo D <43831545+AngeloD2022@users.noreply.github.com> Date: Wed, 29 Nov 2023 18:19:59 -0500 Subject: [PATCH 2/4] Adapted test to prior changes. --- tests/test_main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index 83fdde5..57ea011 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -20,8 +20,8 @@ def test_versions(monkeypatch): assert get.calls == [pretend.call("https://pypi.org/pypi/foo/json")] assert render_template.calls == [ pretend.call( - "links.html", - links=["./0.5.1e"], + "releases.html", + releases={"0.5.1e": None}, h2="foo", h2_link="/project/foo", h2_paren="View this project on PyPI", From c232b16ab30f38381c6975ae372787ed79d54ee2 Mon Sep 17 00:00:00 2001 From: Angelo D <43831545+AngeloD2022@users.noreply.github.com> Date: Wed, 22 May 2024 12:51:49 -0400 Subject: [PATCH 3/4] Add monaco editor for code view. --- inspector/static/style.css | 18 ++++++++++++++++++ inspector/templates/code.html | 34 ++++++++++++++++++++++++++++++---- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/inspector/static/style.css b/inspector/static/style.css index e27feae..c4d4a83 100644 --- a/inspector/static/style.css +++ b/inspector/static/style.css @@ -24,3 +24,21 @@ table, th, td { .no-entries { color: grey; } + +html, body { + margin: 0; + padding: 4px; + height: 115%; + /*overflow: hidden; !* Prevent scrollbars *!*/ +} + +#editor { + width: 100%; + height: 85vh; +} + + +#editor-container { + margin: 25px; + border: 1px solid lightgray; +} diff --git a/inspector/templates/code.html b/inspector/templates/code.html index 210e985..783d698 100644 --- a/inspector/templates/code.html +++ b/inspector/templates/code.html @@ -3,6 +3,7 @@ {% block head %} + {% endblock %} {% block above_body %} @@ -18,9 +19,34 @@ {% block body %} Report Malicious Package -
+{#
#}
 {# Indenting the below  tag will cause rendering issues! #}
-{{- code }}
-
- +{#{{- code }}#} +{#
#} +
+
+
+ + + {% endblock %} From 5362e2b28098f3479e203b7ab0ad127258f764b2 Mon Sep 17 00:00:00 2001 From: Angelo D <43831545+AngeloD2022@users.noreply.github.com> Date: Wed, 22 May 2024 14:00:34 -0400 Subject: [PATCH 4/4] Fix version discrepancy. --- inspector/templates/code.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inspector/templates/code.html b/inspector/templates/code.html index 783d698..c476e63 100644 --- a/inspector/templates/code.html +++ b/inspector/templates/code.html @@ -27,7 +27,7 @@
- +