2020-02-13 16:29:40 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import json
|
2023-06-17 08:05:06 +00:00
|
|
|
import logging as log
|
2020-02-13 16:29:40 +00:00
|
|
|
import os
|
|
|
|
import sys
|
2023-06-17 08:05:06 +00:00
|
|
|
|
|
|
|
log.basicConfig(level=log.INFO, format="%(levelname)s: %(message)s")
|
2020-02-13 16:29:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
def key(v):
|
2023-06-17 08:05:06 +00:00
|
|
|
if v == "master":
|
|
|
|
return float("inf")
|
|
|
|
if v == "stable":
|
2020-02-13 16:29:40 +00:00
|
|
|
return sys.maxsize
|
2023-06-17 08:05:06 +00:00
|
|
|
if v == "beta":
|
2020-03-25 19:01:11 +00:00
|
|
|
return sys.maxsize - 1
|
2023-06-17 08:05:06 +00:00
|
|
|
if v == "pre-1.29.0":
|
|
|
|
return -1
|
2020-02-13 16:29:40 +00:00
|
|
|
|
2023-06-17 08:05:06 +00:00
|
|
|
v = v.replace("rust-", "")
|
2020-02-13 16:29:40 +00:00
|
|
|
|
|
|
|
s = 0
|
2023-06-17 08:05:06 +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():
|
|
|
|
if len(sys.argv) < 2:
|
2021-07-28 12:15:34 +00:00
|
|
|
log.error("specify output directory")
|
2020-02-13 16:29:40 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
outdir = sys.argv[1]
|
|
|
|
versions = [
|
2023-06-17 08:05:06 +00:00
|
|
|
dir
|
|
|
|
for dir in os.listdir(outdir)
|
|
|
|
if not dir.startswith(".")
|
|
|
|
and not dir.startswith("v")
|
|
|
|
and os.path.isdir(os.path.join(outdir, dir))
|
2020-02-13 16:29:40 +00:00
|
|
|
]
|
|
|
|
versions.sort(key=key)
|
|
|
|
|
|
|
|
with open(os.path.join(outdir, "versions.json"), "w") as fp:
|
|
|
|
json.dump(versions, fp, indent=2)
|
|
|
|
log.info("wrote JSON for great justice")
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|