summaryrefslogtreecommitdiff
path: root/Omni/Dev
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2024-05-29 16:32:22 -0400
committerBen Sima <ben@bsima.me>2025-01-06 13:28:32 -0500
commit4a1ce4ecad5b4d41494f65887a7094685739e75b (patch)
tree62445dbf5389100619c04ada407b4687e7391ad0 /Omni/Dev
parent110edf2465856a2eff75b57ba4eb37b276b9b1c4 (diff)
Add GitStats server
I often want to view gitstats but I always forget how to generate and view them, so this script simply captures this workflow and tests that it continues to work.
Diffstat (limited to 'Omni/Dev')
-rwxr-xr-xOmni/Dev/GitStats.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/Omni/Dev/GitStats.py b/Omni/Dev/GitStats.py
new file mode 100755
index 0000000..8a6328d
--- /dev/null
+++ b/Omni/Dev/GitStats.py
@@ -0,0 +1,50 @@
+#!/usr/bin/env run.sh
+# : run gitstats
+# : out gitstats-serve
+"""
+Show gitstats for the omnirepo.
+
+Generates gitstats HTML output in _/var, then starts a webserver to serve that
+directory.
+"""
+
+import http.server
+import os
+import pathlib
+import subprocess
+import sys
+
+
+def main() -> None:
+ """Serve gitstats on localhost:8000.
+
+ Raises:
+ ValueError: if CODEROOT is not set
+ """
+ if "test" in sys.argv:
+ # test that gitstats in available, and exit
+ sys.exit(subprocess.run(["which", "gitstats"], check=False).returncode)
+ root = os.getenv("CODEROOT")
+ if root is None:
+ msg = "CODEROOT is not set"
+ raise ValueError(msg)
+ omni_dir = pathlib.Path(root)
+ out_dir = omni_dir / "_" / "var" / "gitstats"
+ subprocess.check_call([
+ "gitstats",
+ str(omni_dir),
+ str(out_dir),
+ ])
+ addr = ("", 8000)
+ handler = http.server.SimpleHTTPRequestHandler
+ pwd = pathlib.Path.cwd()
+ os.chdir(out_dir)
+ with http.server.HTTPServer(addr, handler) as httpd:
+ host, port = httpd.socket.getsockname()[:2]
+ sys.stdout.write(f"serving gitstats on http://{host}:{port}\n")
+ sys.stdout.flush()
+ try:
+ httpd.serve_forever()
+ except KeyboardInterrupt:
+ sys.stdout.write("\nstopping httpd\n")
+ os.chdir(pwd)