|
| 1 | +importargparse |
1 | 2 | importglob
|
| 3 | +importlogging |
| 4 | +importmultiprocessing |
2 | 5 | importos
|
3 |
| -importsubprocess |
4 | 6 | importpathlib
|
5 |
| -importtempfile |
6 | 7 | importre
|
7 |
| -importlogging |
| 8 | +importsubprocess |
| 9 | +importsys |
| 10 | +importtempfile |
| 11 | + |
8 | 12 |
|
9 | 13 | """
|
10 | 14 | This script does two things that improve the website organization.
|
@@ -152,30 +156,47 @@ def update_canonical(fullname, last):
|
152 | 156 | os.rename(fout.name,fullname)
|
153 | 157 |
|
154 | 158 |
|
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 | + |
156 | 175 | # html redirect or soft link most things in the top-level directory that
|
157 | 176 | # 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') |
179 | 194 |
|
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) |