#!/usr/bin/env python3 import os import re from pathlib import Path from typing import List BASE_URL = "https://huggingface.co/csukuangfj/sherpa-onnx-wheels/resolve/main/" from dataclasses import dataclass @dataclass class Wheel: major: int minor: int patch: int python: str os: str def __init__(self, _s): # sherpa_onnx-1.10.16-cp38-cp38-macosx_11_0_x86_64.whl s = _s.split("/")[-1] split = s.split("-") self.major, self.minor, self.patch = list(map(int, split[1].split("."))) self.python = int(split[2][2:]) self.os = split[4] def sort_by_wheel(x): x = Wheel(x) return (x.major, x.minor, x.patch, x.python, x.os) def get_all_files(d: str, suffix: str = ".whl") -> List[str]: ss = [] for root, d, files in os.walk(d): for f in files: if f.endswith(suffix): ss.append(os.path.join(root, f)) return list(map(lambda x: BASE_URL + x, ss)) def main(): wheel = get_all_files("cpu") wheel = sorted(wheel, key=sort_by_wheel, reverse=True) wheel_cn = [] for w in wheel: w = w.replace("huggingface.co", "hf-mirror.com") wheel_cn.append(w) with open("cpu.html", "w") as f: for w in wheel: basename = w.split("/")[-1] f.write(f'{basename}
\n') with open("cpu-cn.html", "w") as f: for w in wheel_cn: basename = w.split("/")[-1] f.write(f'{basename}
\n') if __name__ == "__main__": main()