|
| 1 | +#!/usr/bin/env python3 |
| 2 | +from __future__ import annotations |
| 3 | + |
| 4 | +import argparse |
| 5 | +import os.path |
| 6 | +import shutil |
| 7 | +import subprocess |
| 8 | +import sys |
| 9 | +import tempfile |
| 10 | +import urllib.parse |
| 11 | +import urllib.request |
| 12 | +from collections.abc import Sequence |
| 13 | + |
| 14 | + |
| 15 | +def main(argv: Sequence[str] | None = None) -> int: |
| 16 | + parser = argparse.ArgumentParser() |
| 17 | + parser.add_argument("--pypi-url", required=True) |
| 18 | + args = parser.parse_args(argv) |
| 19 | + |
| 20 | + url = urllib.parse.urljoin(args.pypi_url, "packages.json") |
| 21 | + |
| 22 | + with tempfile.TemporaryDirectory() as tmpdir: |
| 23 | + packages_json = f"{tmpdir}/packages.json" |
| 24 | + with urllib.request.urlopen(url) as resp, open(packages_json, "wb") as f: |
| 25 | + shutil.copyfileobj(resp, f) |
| 26 | + |
| 27 | + index = f"{tmpdir}/index" |
| 28 | + os.makedirs(index) |
| 29 | + |
| 30 | + subprocess.check_call( |
| 31 | + ( |
| 32 | + sys.executable, |
| 33 | + "-mdumb_pypi.main", |
| 34 | + f"--package-list-json={packages_json}", |
| 35 | + f"--output-dir={index}", |
| 36 | + f'--packages-url={urllib.parse.urljoin(args.pypi_url, "wheels")}', |
| 37 | + "--title=sentry pypi", |
| 38 | + "--logo=https://avatars.githubusercontent.com/u/1396951?s=24", |
| 39 | + "--logo-width=36", |
| 40 | + ) |
| 41 | + ) |
| 42 | + |
| 43 | + subprocess.check_call( |
| 44 | + ( |
| 45 | + "gcloud", |
| 46 | + "storage", |
| 47 | + "cp", |
| 48 | + # clobber, no caching |
| 49 | + "--cache-control", |
| 50 | + "no-store", |
| 51 | + "-r", |
| 52 | + *(os.path.join(index, name) for name in os.listdir(index)), |
| 53 | + "gs://pypi.devinfra.sentry.io", |
| 54 | + ) |
| 55 | + ) |
| 56 | + |
| 57 | + return 0 |
| 58 | + |
| 59 | + |
| 60 | +if __name__ == "__main__": |
| 61 | + raise SystemExit(main()) |
0 commit comments