2020-02-13 16:29:40 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2024-09-24 09:58:04 +00:00
|
|
|
from string import Template
|
|
|
|
import argparse
|
2020-02-13 16:29:40 +00:00
|
|
|
import os
|
|
|
|
import sys
|
2023-07-02 12:35:19 +00:00
|
|
|
|
2020-02-13 16:29:40 +00:00
|
|
|
def key(v):
|
2023-07-02 12:35:19 +00:00
|
|
|
if v == "master":
|
2020-02-13 16:29:40 +00:00
|
|
|
return sys.maxsize
|
2024-09-24 09:58:04 +00:00
|
|
|
if v == "stable":
|
2020-03-25 19:01:11 +00:00
|
|
|
return sys.maxsize - 1
|
2024-09-24 09:58:04 +00:00
|
|
|
if v == "beta":
|
|
|
|
return sys.maxsize - 2
|
2023-07-02 12:35:19 +00:00
|
|
|
if v == "pre-1.29.0":
|
|
|
|
return -1
|
2024-09-24 09:58:04 +00:00
|
|
|
if not v.startswith("rust-"):
|
|
|
|
return None
|
2020-02-13 16:29:40 +00:00
|
|
|
|
2023-07-02 12:35:19 +00:00
|
|
|
v = v.replace("rust-", "")
|
2020-02-13 16:29:40 +00:00
|
|
|
|
|
|
|
s = 0
|
2023-07-02 12:35:19 +00:00
|
|
|
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-24 09:58:04 +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 = [
|
2023-07-02 12:35:19 +00:00
|
|
|
dir
|
2024-09-24 09:58:04 +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-24 09:58:04 +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-24 09:58:04 +00:00
|
|
|
template = Template(args.input.read())
|
|
|
|
html = template.substitute(list="\n".join(links))
|
2020-02-13 16:29:40 +00:00
|
|
|
|
2024-09-24 09:58:04 +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()
|