rust-clippy/util/versions.py

53 lines
1.3 KiB
Python
Raw Normal View History

2020-02-13 16:29:40 +00:00
#!/usr/bin/env python
2024-09-18 17:17:16 +00:00
from string import Template
import argparse
2020-02-13 16:29:40 +00:00
import json
import os
import sys
2020-02-13 16:29:40 +00:00
def key(v):
if v == "master":
2020-02-13 16:29:40 +00:00
return sys.maxsize
2024-09-18 17:17:16 +00:00
if v == "stable":
2020-03-25 19:01:11 +00:00
return sys.maxsize - 1
2024-09-18 17:17:16 +00:00
if v == "beta":
return sys.maxsize - 2
if v == "pre-1.29.0":
return -1
2024-09-18 17:17:16 +00:00
if not v.startswith("rust-"):
return None
2020-02-13 16:29:40 +00:00
v = v.replace("rust-", "")
2020-02-13 16:29:40 +00:00
s = 0
for i, val in enumerate(v.split(".")[::-1]):
2020-02-13 16:29:40 +00:00
s += int(val) * 100**i
return s
def main():
2024-09-18 17:17:16 +00:00
parser = argparse.ArgumentParser()
parser.add_argument("input", help="path to the versions.html template", type=argparse.FileType("r"))
parser.add_argument("outdir", help="path to write the output HTML")
args = parser.parse_args()
2020-02-13 16:29:40 +00:00
versions = [
dir
2024-09-18 17:17:16 +00:00
for dir in os.listdir(args.outdir)
if key(dir) is not None
2020-02-13 16:29:40 +00:00
]
2024-09-18 17:17:16 +00:00
versions.sort(key=key, reverse=True)
links = [f'<a class="list-group-item" href="./{version}/index.html">{version}</a>' for version in versions]
2020-02-13 16:29:40 +00:00
2024-09-18 17:17:16 +00:00
template = Template(args.input.read())
html = template.substitute(list="\n".join(links))
2020-02-13 16:29:40 +00:00
2024-09-18 17:17:16 +00:00
path = os.path.join(args.outdir, "index.html")
with open(path, "w") as out:
out.write(html)
print(f"wrote HTML to {path}")
2020-02-13 16:29:40 +00:00
if __name__ == "__main__":
main()