summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2024-01-09 11:54:17 +0200
committerLars Wirzenius <liw@liw.fi>2024-01-09 11:54:17 +0200
commit168b450510e06739ba4c4b080264a40e7309e788 (patch)
tree6e2b32882c7bc16a002a35807168e91369b3b566
parent8f95c76a46e4891f89379d4fd62952f42cfa2086 (diff)
downloadwumpus-hunter-168b450510e06739ba4c4b080264a40e7309e788.tar.gz
feat: generate a nicer HTML page
Commits are now ordered by commit date, newest first. Also, the commit id is a link to the directory with the log files for that commit. The list of commits is now a table. There is some CSS. Signed-off-by: Lars Wirzenius <liw@liw.fi>
-rwxr-xr-xwumpus-hunter58
1 files changed, 47 insertions, 11 deletions
diff --git a/wumpus-hunter b/wumpus-hunter
index d7431e2..b70478b 100755
--- a/wumpus-hunter
+++ b/wumpus-hunter
@@ -27,6 +27,19 @@ Only logs from failed runs are kept.
"""
+CSS = """
+table {
+ width: 100%;
+ text-align: left;
+ tr:nth-child(even) {background-color: #f2f2f2;}
+}
+
+.numeric {
+ text-align: right;
+}
+"""
+
+
def parse_args():
p = argparse.ArgumentParser()
p.add_argument(
@@ -191,7 +204,25 @@ def rename_log(log, dirname, commit):
os.rename(log, run_log)
-def count(counts, stats):
+def git_commit_date(dirname, commit):
+ try:
+ out = git(
+ "show",
+ "--pretty=medium",
+ "--date=iso",
+ commit,
+ cwd=dirname,
+ )
+ except Exception:
+ return "(unknown commit)"
+ prefix = "Date:"
+ date = [line.strip() for line in out.splitlines() if line.startswith(prefix)][0]
+ if date.startswith(prefix):
+ date = date[len(prefix) :].strip()
+ return date
+
+
+def count(src, counts, stats):
d = {}
with open(stats) as f:
for line in f:
@@ -204,23 +235,28 @@ def count(counts, stats):
else:
fail += 1
d[commit] = (succ, fail)
+
+ commits = [(git_commit_date(src, commit), commit) for commit in d]
+
with open(counts, "w") as f:
f.write("<html>\n")
f.write("<head>\n")
f.write("<title>Radicle Wumpus hunter</title>\n")
+ f.write(f"<style>{CSS}</style>\n")
f.write("</head>\n")
f.write("<body>\n")
f.write(EXPLANATION_HTML)
- f.write("<ol>\n")
- for commit in sorted(d.keys()):
+ f.write("<table>\n")
+ f.write(
+ "<tr><th>Date</th><th>commit</th><th class=numeric>successes</th><th class=numeric>failures</th></tr>\n"
+ )
+ for date, commit in sorted(commits):
(succ, fail) = d[commit]
- f.write(f"<li><code>{commit}</code> {succ} ")
- if fail:
- f.write(f"{fail}</a>")
- else:
- f.write(f"{fail}")
- f.write(f"</li>\n")
- f.write("</oi>\n")
+ link = f'<a href="log-{commit}/"><code>{commit}</code></a>'
+ f.write(
+ f"<tr><td>{date}</td><td>{link}</td><td class=numeric>{succ}</td><td class=numeric>{fail}</td></tr>\n"
+ )
+ f.write("</table>\n")
timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
f.write(f"<p>Last updated {timestamp}</p>\n")
f.write("</body>\n")
@@ -248,7 +284,7 @@ def main():
rename_log(args.log, args.run_log, commit)
if args.counts:
- count(args.counts, args.stats)
+ count(args.dir, args.counts, args.stats)
main()