Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0f393a5

Browse files
committed
FIX: update make_links
1 parent 3aa7fe4 commit 0f393a5

File tree

1 file changed

+48
-27
lines changed

1 file changed

+48
-27
lines changed

_websiteutils/make_redirects_links.py

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
import argparse
12
import glob
3+
import logging
4+
import multiprocessing
25
import os
3-
import subprocess
46
import pathlib
5-
import tempfile
67
import re
7-
import logging
8+
import subprocess
9+
import sys
10+
import tempfile
11+
812

913
"""
1014
This script does two things that improve the website organization.
@@ -152,30 +156,47 @@ def update_canonical(fullname, last):
152156
os.rename(fout.name, fullname)
153157

154158

155-
def main():
159+
if __name__ == "__main__":
160+
161+
parser = argparse.ArgumentParser(description='Optional app description')
162+
163+
parser.add_argument('--np', type=int, help='Number of processors to use')
164+
parser.add_argument('--no_canonicals', help='do not do canonical links',
165+
action="store_true")
166+
parser.add_argument('--no_redirects', help='do not do redirects links',
167+
action="store_true")
168+
169+
args = parser.parse_args()
170+
if args.np:
171+
np = args.np
172+
else:
173+
np = None
174+
156175
# html redirect or soft link most things in the top-level directory that
157176
# are not other modules or versioned docs.
158-
for entry in os.scandir('./'):
159-
if not (entry.name in toignore):
160-
if entry.is_dir():
161-
do_links(entry.name)
162-
elif entry.name.endswith(('.htm', '.html')):
163-
fullname = entry.name
164-
last = findlast(fullname, tocheck)
165-
_log.debug(f'Checking: {fullname} found {last}')
166-
if last is not None:
167-
os.remove('./'+fullname)
168-
_log.info(f'Rewriting HTML: {fullname} in {last}')
169-
with open(fullname, 'w') as fout:
170-
oldname = '/' + os.path.join(last, fullname)
171-
st = html_redirect % (oldname, oldname, oldname)
172-
fout.write(st)
173-
_log.info('Done links and redirects')
174-
# change the canonical url for all html to the newest version in the docs:
175-
176-
pool = multiprocessing.Pool()
177-
pool.map(do_canonicals, tocheck[1:])
178-
pool.close()
177+
if not args.no_redirects:
178+
for entry in os.scandir('./'):
179+
if not (entry.name in toignore):
180+
if entry.is_dir():
181+
do_links(entry.name)
182+
elif entry.name.endswith(('.htm', '.html')):
183+
fullname = entry.name
184+
last = findlast(fullname, tocheck)
185+
_log.debug(f'Checking: {fullname} found {last}')
186+
if last is not None:
187+
os.remove('./'+fullname)
188+
_log.info(f'Rewriting HTML: {fullname} in {last}')
189+
with open(fullname, 'w') as fout:
190+
oldname = '/' + os.path.join(last, fullname)
191+
st = html_redirect % (oldname, oldname, oldname)
192+
fout.write(st)
193+
_log.info('Done links and redirects')
179194

180-
if __name__ == "__main__":
181-
main()
195+
# change the canonical url for all html to the newest version in the docs:
196+
if not args.no_canonicals:
197+
if np is not None:
198+
with multiprocessing.Pool(np) as pool:
199+
pool.map(do_canonicals, tocheck[1:])
200+
else:
201+
for t in tocheck[1:]:
202+
do_canonicals(t)

0 commit comments

Comments
 (0)