43
43
44
44
import zc .lockfile
45
45
import jinja2
46
+ import requests
46
47
47
48
HERE = Path (__file__ ).resolve ().parent
48
49
@@ -508,14 +509,7 @@ def build_robots_txt(www_root: Path, group, skip_cache_invalidation):
508
509
robots_file .chmod (0o775 )
509
510
run (["chgrp" , group , robots_file ])
510
511
if not skip_cache_invalidation :
511
- run (
512
- [
513
- "curl" ,
514
- "--silent" ,
515
- "-XPURGE" ,
516
- "https://docs.python.org/robots.txt" ,
517
- ]
518
- )
512
+ requests .request ("PURGE" , "https://docs.python.org/robots.txt" )
519
513
520
514
521
515
def build_sitemap (www_root : Path ):
@@ -968,7 +962,7 @@ def dev_symlink(www_root: Path, group):
968
962
symlink (www_root , language , current_dev , "dev" , group )
969
963
970
964
971
- def proofread_canonicals (www_root : Path ) -> None :
965
+ def proofread_canonicals (www_root : Path , skip_cache_invalidation : bool ) -> None :
972
966
"""In www_root we check that all canonical links point to existing contents.
973
967
974
968
It can happen that a canonical is "broken":
@@ -989,6 +983,10 @@ def proofread_canonicals(www_root: Path) -> None:
989
983
logging .info ("Removing broken canonical from %s to %s" , file , target )
990
984
html = html .replace (canonical .group (0 ), "" )
991
985
file .write_text (html , encoding = "UTF-8" , errors = "surrogateescape" )
986
+ if not skip_cache_invalidation :
987
+ url = str (file ).replace ("/srv/" , "https://" )
988
+ logging .info ("Purging %s from CDN" , url )
989
+ requests .request ("PURGE" , url )
992
990
993
991
994
992
def main ():
@@ -1023,7 +1021,7 @@ def main():
1023
1021
build_robots_txt (args .www_root , args .group , args .skip_cache_invalidation )
1024
1022
major_symlinks (args .www_root , args .group )
1025
1023
dev_symlink (args .www_root , args .group )
1026
- proofread_canonicals (args .www_root )
1024
+ proofread_canonicals (args .www_root , args . skip_cache_invalidation )
1027
1025
1028
1026
1029
1027
if __name__ == "__main__" :
0 commit comments