From 97e3bad5dc1557c9ebcd827574e7e552a81c8499 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 12 Feb 2019 18:26:25 -0500 Subject: [PATCH] Use faster log rendering implementation --- buildsrht/blueprints/jobs.py | 16 ++++++++++++++-- buildsrht/templates/job.html | 9 +-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/buildsrht/blueprints/jobs.py b/buildsrht/blueprints/jobs.py index 78b4df5..6916479 100644 --- a/buildsrht/blueprints/jobs.py +++ b/buildsrht/blueprints/jobs.py @@ -8,6 +8,7 @@ from srht.validation import Validation from buildsrht.types import Job, JobStatus, Task, TaskStatus, User from buildsrht.manifest import Manifest from buildsrht.runner import queue_build +from jinja2 import Markup, escape import hashlib import requests import yaml @@ -214,6 +215,17 @@ def tag_svg(username, path): .filter(Job.tags.ilike(path + "%")) return svg_page(jobs) +def logify(text, task): + text = Markup('
') + escape(text) + Markup('
') + nlines = text.encode().count(b'\n') + linenos = Markup('
')
+    for no in range(1, nlines + 1):
+        linenos += Markup(f"{no}")
+        if no != nlines:
+            linenos += Markup("\n")
+    linenos += Markup("
") + return Markup('') + linenos + Markup('') + text + Markup('') + @jobs.route("/~/job/") def job_by_id(username, job_id): # TODO: maybe we want per-user job IDs @@ -226,7 +238,7 @@ def job_by_id(username, job_id): if r.status_code == 200: logs.append({ "name": None, - "log": r.text.splitlines() + "log": logify(r.text, "setup") }) except: pass @@ -245,7 +257,7 @@ def job_by_id(username, job_id): if r.status_code == 200: logs.append({ "name": task.name, - "log": r.text.splitlines() + "log": logify(r.text, "task-" + task.name) }) return render_template("job.html", job=job, diff --git a/buildsrht/templates/job.html b/buildsrht/templates/job.html index 8d2dc92..837376f 100644 --- a/buildsrht/templates/job.html +++ b/buildsrht/templates/job.html @@ -112,14 +112,7 @@ {% endif %} - - + {{log["log"]}}
-
{% for line in log["log"] %}{{loop.index}}{% if not loop.last %}
-{% endif %}{% endfor %}
-
-
{% for line in log["log"] %}{{ line }}{% if not loop.last %}
-{% endif %}{% endfor %}
-
-- 2.38.5