|
11 | 11 | import contextlib
|
12 | 12 | import functools
|
13 | 13 | import getpass
|
| 14 | +import http.client |
14 | 15 | import json
|
15 | 16 | import os
|
16 | 17 | import re
|
@@ -942,22 +943,24 @@ def purge_the_cdn(db: ReleaseShelf) -> None:
|
942 | 943 | "https://www.python.org/downloads/windows/",
|
943 | 944 | "https://www.python.org/downloads/macos/",
|
944 | 945 | ]
|
945 |
| - # Purge the source URLs and their associated metadata files. |
946 |
| - source_urls = [ |
947 |
| - f"https://www.python.org/ftp/python/{normalized_release}/Python-{db['release']}.tgz", |
948 |
| - f"https://www.python.org/ftp/python/{normalized_release}/Python-{db['release']}.tar.xz", |
949 |
| - ] |
950 |
| - for source_url in source_urls: |
951 |
| - urls.extend( |
952 |
| - [ |
953 |
| - f"{source_url}", |
954 |
| - f"{source_url}.asc", |
955 |
| - f"{source_url}.crt", |
956 |
| - f"{source_url}.sig", |
957 |
| - f"{source_url}.sigstore", |
958 |
| - f"{source_url}.spdx.json", |
959 |
| - ] |
960 |
| - ) |
| 946 | + |
| 947 | + # Recursively discover artifacts to purge. |
| 948 | + ftp_download_pages = [f"https://www.python.org/ftp/python/{normalized_release}/"] |
| 949 | + while ftp_download_pages: |
| 950 | + ftp_download_page = ftp_download_pages.pop(0) |
| 951 | + req = urllib.request.Request(method="GET", url=ftp_download_page, headers=headers) |
| 952 | + resp = urllib.request.urlopen(req) |
| 953 | + if resp.code != 200: |
| 954 | + raise RuntimeError("Failed to purge the python.org/downloads CDN") |
| 955 | + for link in re.findall(r"<a href=\"([^\"]+)\">", resp.read().decode()): |
| 956 | + if link in ("../", "./"): # Special value, ignore it. |
| 957 | + continue |
| 958 | + |
| 959 | + if link.endswith("/"): # Directory, recurse into it. |
| 960 | + ftp_download_pages.append(f"{ftp_download_page}{link}") |
| 961 | + |
| 962 | + # We want to purge both directories and files. |
| 963 | + urls.append(f"{ftp_download_page}{link}") |
961 | 964 |
|
962 | 965 | for url in urls:
|
963 | 966 | req = urllib.request.Request(url=url, headers=headers, method="PURGE")
|
|
0 commit comments