Commit 3f1e3ef4 authored by Mathieu Giraud's avatar Mathieu Giraud

tools/validate-links.py: displays stats, exit 1 when one link is failing

parent 00dea500
......@@ -5,6 +5,7 @@ import glob
import sys
from urllib.parse import *
import re
from collections import defaultdict
DEFAULT_FILES = glob.glob('../site/*/*.html')
......@@ -17,6 +18,8 @@ STATUS = {
True: 'ok'
}
stats = defaultdict(int)
def check_url(url, ids=[]):
# Internal links
......@@ -44,7 +47,15 @@ def check_file(f):
for url in REGEX_HREF.findall(content):
ok = check_url(url, ids)
print(STATUS[ok] + ' ' + url)
globals()['stats'][ok] += 1
print()
def print_stats():
print('==== Summary')
for k, v in STATUS.items():
print(' %s : %3d' % (v, globals()['stats'][k]))
if __name__ == '__main__':
......@@ -52,4 +63,7 @@ if __name__ == '__main__':
for f in files:
check_file(f)
print_stats()
if globals()['stats'][False]:
sys.exit(1)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment