From c59a7cd871bf29d123481b2e5b0bd739b064f15f Mon Sep 17 00:00:00 2001 From: Andrew Turner Date: Sat, 19 Oct 2019 10:18:13 +0000 Subject: tools: Run 2to3 on check_links.py The python binary may not be Python 2. Support Python 3 by running the 2to3 conversion tool on it. This has been tested with both Python 2 and 3. --- tools/check_links.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'tools/check_links.py') diff --git a/tools/check_links.py b/tools/check_links.py index 269e323ab..cf6530b49 100755 --- a/tools/check_links.py +++ b/tools/check_links.py @@ -1,5 +1,6 @@ #!/usr/bin/python +from __future__ import print_function import os import re import sys @@ -7,7 +8,7 @@ import sys link_re = re.compile('\[' + '[^\[\]]+' + '\]' + '\(' + '([^\(\)]+)' + '\)') if len(sys.argv) < 3: - print 'Usage: ...' + print('Usage: ...') sys.exit(1) root = sys.argv[1] @@ -22,7 +23,8 @@ for doc in docs: for link in r: links += [(doc, link)] -def filter_link((doc, link)): +def filter_link(args): + (doc, link) = args if link.startswith('http'): return False if link.startswith('#'): @@ -31,18 +33,20 @@ def filter_link((doc, link)): return False return True -links = filter(filter_link, links) +links = list(filter(filter_link, links)) -def fix_link((doc, link)): +def fix_link(args): + (doc, link) = args link = link.split('#')[0] link = link.split('?')[0] return (doc, link) -links = map(fix_link, links) +links = list(map(fix_link, links)) errors = [] -def check_link((doc, link)): +def check_link(args): + (doc, link) = args path = os.path.dirname(doc) full_link = None if link[0] == '/': @@ -59,10 +63,10 @@ for link in links: errors += [link] if len(errors) == 0: - print '%d links checked: OK' % (len(links),) + print('%d links checked: OK' % (len(links),)) sys.exit(0) for (doc, link) in errors: - print 'File %s linked from %s not found' % (link, doc) + print('File %s linked from %s not found' % (link, doc)) sys.exit(2) -- cgit mrf-deployment