|
2 | 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this
|
3 | 3 | # file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
4 | 4 |
|
| 5 | +import collections |
5 | 6 | import gzip
|
6 | 7 | import hashlib
|
7 | 8 | import http.client
|
@@ -579,14 +580,49 @@ def validate_python_json(info, extension_modules):
|
579 | 580 | )
|
580 | 581 |
|
581 | 582 |
|
582 |
| -def release_download_statistics(): |
| 583 | +def release_download_statistics(mode="by_asset"): |
583 | 584 | with urllib.request.urlopen(
|
584 | 585 | "https://api.github.com/repos/indygreg/python-build-standalone/releases"
|
585 | 586 | ) as fh:
|
586 | 587 | data = json.load(fh)
|
587 | 588 |
|
| 589 | + by_tag = collections.Counter() |
| 590 | + by_build = collections.Counter() |
| 591 | + by_build_install_only = collections.Counter() |
| 592 | + |
588 | 593 | for release in data:
|
589 | 594 | tag = release["tag_name"]
|
590 | 595 |
|
591 | 596 | for asset in release["assets"]:
|
592 |
| - print("%d\t%s\t%s" % (asset["download_count"], tag, asset["name"])) |
| 597 | + name = asset["name"] |
| 598 | + count = asset["download_count"] |
| 599 | + |
| 600 | + by_tag[tag] += count |
| 601 | + |
| 602 | + if name.endswith(".tar.zst"): |
| 603 | + # cpython-3.10.2-aarch64-apple-darwin-debug-20220220T1113.tar.zst |
| 604 | + build_parts = name.split("-") |
| 605 | + build = "-".join(build_parts[2:-1]) |
| 606 | + by_build[build] += count |
| 607 | + elif name.endswith("install_only.tar.gz"): |
| 608 | + # cpython-3.10.13+20240224-x86_64-apple-darwin-install_only.tar.gz |
| 609 | + build_parts = name.split("-") |
| 610 | + build = "-".join(build_parts[2:-1]) |
| 611 | + by_build_install_only[build] += count |
| 612 | + |
| 613 | + if mode == "by_asset": |
| 614 | + print("%d\t%s\t%s" % (count, tag, name)) |
| 615 | + |
| 616 | + if mode == "by_build": |
| 617 | + for build, count in sorted(by_build.items()): |
| 618 | + print("%d\t%s" % (count, build)) |
| 619 | + elif mode == "by_build_install_only": |
| 620 | + for build, count in sorted(by_build_install_only.items()): |
| 621 | + print("%d\t%s" % (count, build)) |
| 622 | + elif mode == "by_tag": |
| 623 | + for tag, count in sorted(by_tag.items()): |
| 624 | + print("%d\t%s"% (count, tag)) |
| 625 | + elif mode == "total": |
| 626 | + print("%d" % by_tag.total()) |
| 627 | + else: |
| 628 | + raise Exception("unhandled display mode: %s" % mode) |
0 commit comments