Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0f393a5

Browse files
committed
FIX: update make_links
1 parent3aa7fe4 commit0f393a5

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+
importargparse
12
importglob
3+
importlogging
4+
importmultiprocessing
25
importos
3-
importsubprocess
46
importpathlib
5-
importtempfile
67
importre
7-
importlogging
8+
importsubprocess
9+
importsys
10+
importtempfile
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-
defmain():
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+
ifargs.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-
forentryinos.scandir('./'):
159-
ifnot (entry.nameintoignore):
160-
ifentry.is_dir():
161-
do_links(entry.name)
162-
elifentry.name.endswith(('.htm','.html')):
163-
fullname=entry.name
164-
last=findlast(fullname,tocheck)
165-
_log.debug(f'Checking:{fullname} found{last}')
166-
iflastisnotNone:
167-
os.remove('./'+fullname)
168-
_log.info(f'Rewriting HTML:{fullname} in{last}')
169-
withopen(fullname,'w')asfout:
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+
ifnotargs.no_redirects:
178+
forentryinos.scandir('./'):
179+
ifnot (entry.nameintoignore):
180+
ifentry.is_dir():
181+
do_links(entry.name)
182+
elifentry.name.endswith(('.htm','.html')):
183+
fullname=entry.name
184+
last=findlast(fullname,tocheck)
185+
_log.debug(f'Checking:{fullname} found{last}')
186+
iflastisnotNone:
187+
os.remove('./'+fullname)
188+
_log.info(f'Rewriting HTML:{fullname} in{last}')
189+
withopen(fullname,'w')asfout:
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+
ifnotargs.no_canonicals:
197+
ifnpisnotNone:
198+
withmultiprocessing.Pool(np)aspool:
199+
pool.map(do_canonicals,tocheck[1:])
200+
else:
201+
fortintocheck[1:]:
202+
do_canonicals(t)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp