aboutsummaryrefslogtreecommitdiffstats
path: root/tools/check_links.py
diff options
context:
space:
mode:
authorAndrew Turner <andrew@fubar.geek.nz>2019-10-19 10:18:13 +0000
committerAndrey Konovalov <andreyknvl@gmail.com>2019-10-21 15:56:27 +0200
commitc59a7cd871bf29d123481b2e5b0bd739b064f15f (patch)
tree6a8571a844823c16cd87b6e097b44ea8e0a70f68 /tools/check_links.py
parent061a8b8a29c009ff72665514e53984c1783d6ca6 (diff)
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.
Diffstat (limited to 'tools/check_links.py')
-rwxr-xr-xtools/check_links.py20
1 files changed, 12 insertions, 8 deletions
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: <root_dir> <doc_files>...'
+ print('Usage: <root_dir> <doc_files>...')
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)