2019-08-19 11:24:51 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2019-08-23 07:27:47 +00:00
|
|
|
import argparse
|
2019-04-01 09:36:13 +00:00
|
|
|
import json
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
from distutils.version import StrictVersion
|
|
|
|
|
|
|
|
|
|
|
|
def get_versions():
|
|
|
|
|
|
|
|
output = subprocess.check_output(
|
|
|
|
["git", "tag", "-l", "--format=%(creatordate:iso-strict)|%(refname:short)"]
|
|
|
|
)
|
|
|
|
tags = []
|
|
|
|
|
|
|
|
for line in output.decode().splitlines():
|
|
|
|
try:
|
|
|
|
date, tag = line.split("|")
|
|
|
|
except (ValueError):
|
|
|
|
continue
|
|
|
|
|
|
|
|
if not date or not tag:
|
|
|
|
continue
|
|
|
|
|
|
|
|
tags.append({"id": tag, "date": date})
|
2019-05-16 11:08:11 +00:00
|
|
|
valid = []
|
|
|
|
for tag in tags:
|
|
|
|
try:
|
|
|
|
StrictVersion(tag["id"])
|
|
|
|
valid.append(tag)
|
|
|
|
except ValueError:
|
|
|
|
continue
|
|
|
|
|
|
|
|
return sorted(valid, key=lambda tag: StrictVersion(tag["id"]), reverse=True)
|
2019-04-01 09:36:13 +00:00
|
|
|
|
|
|
|
|
2019-08-23 07:27:47 +00:00
|
|
|
def main(latest=False):
|
2019-04-01 09:36:13 +00:00
|
|
|
versions = get_versions()
|
2019-08-23 07:27:47 +00:00
|
|
|
if latest:
|
|
|
|
print(versions[0]["id"])
|
|
|
|
else:
|
|
|
|
data = {"count": len(versions), "releases": versions}
|
|
|
|
print(json.dumps(data, sort_keys=True, indent=2))
|
2019-04-01 09:36:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2019-08-23 07:27:47 +00:00
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
"""
|
|
|
|
Compile release data and output in in JSON format
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"-l",
|
|
|
|
"--latest",
|
|
|
|
action="store_true",
|
|
|
|
help="Only print the latest version then exit",
|
|
|
|
)
|
|
|
|
args = parser.parse_args()
|
|
|
|
main(latest=args.latest)
|