summaryrefslogtreecommitdiffstats
path: root/tools/site/check_site.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/site/check_site.py')
-rw-r--r--tools/site/check_site.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/tools/site/check_site.py b/tools/site/check_site.py
index e56d0c0..e79af25 100644
--- a/tools/site/check_site.py
+++ b/tools/site/check_site.py
@@ -72,6 +72,32 @@ def all_titles():
return titles
+def check_external(url_cache, url, problems, title):
+ """HEAD/GET-check a git.vgpu.io URL once; report non-OK statuses."""
+ if url in url_cache:
+ ok, note = url_cache[url]
+ else:
+ ok, note = False, "unchecked"
+ for attempt in range(4):
+ try:
+ req = urllib.request.Request(url, headers=UA, method="GET")
+ with urllib.request.urlopen(req, timeout=60) as r:
+ ok = r.status in (200, 301, 302)
+ note = str(r.status)
+ r.read(1)
+ break
+ except urllib.error.HTTPError as e:
+ ok, note = e.code in (200, 301, 302), str(e.code)
+ if e.code not in (429, 500, 502, 503):
+ break
+ except Exception as e: # noqa: BLE001
+ note = type(e).__name__
+ time.sleep(2 * (attempt + 1))
+ url_cache[url] = (ok, note)
+ if not ok:
+ problems.append(f"repo link {note}: {url}")
+
+
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--pages", nargs="*", default=[])
@@ -79,6 +105,7 @@ def main():
titles = args.pages or all_titles()
existing = {t.lower(): t for t in all_titles()}
+ repo_url_cache = {}
problems = 0
for title in titles:
@@ -117,6 +144,10 @@ def main():
continue
if tgt.lower() not in existing:
issues.append(f"unresolved link [[{tgt}]]")
+ for u in set(re.findall(r"https?://git\.vgpu\.io[^\s\]\}<>\"|]*", c)):
+ u = u.rstrip(".,;:)")
+ check_external(repo_url_cache, u, issues, title)
+ time.sleep(0.2)
if issues:
problems += 1
print(f"BAD {title}")