2020-07-09 00:06:12 +08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# Copyright (c) 2020 Intel Corp.
|
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2020-10-27 22:01:00 +08:00
|
|
|
"""
|
|
|
|
Syntax of file:
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"version": "<commit>",
|
|
|
|
"date": "<date>",
|
|
|
|
"weekly: False,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
"""
|
2020-07-09 00:06:12 +08:00
|
|
|
import json
|
|
|
|
import argparse
|
|
|
|
import urllib.request
|
2020-10-27 22:01:00 +08:00
|
|
|
import os
|
2020-07-09 00:06:12 +08:00
|
|
|
|
|
|
|
from git import Git
|
2020-10-27 22:01:00 +08:00
|
|
|
from datetime import datetime
|
2020-07-09 00:06:12 +08:00
|
|
|
|
|
|
|
VERSIONS_FILE = "versions.json"
|
|
|
|
|
2020-10-27 22:01:00 +08:00
|
|
|
|
2020-07-09 00:06:12 +08:00
|
|
|
def parse_args():
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description="Manage versions to be tested.")
|
|
|
|
parser.add_argument('-l', '--list', action="store_true",
|
2020-10-27 22:01:00 +08:00
|
|
|
help="List all published versions")
|
2020-07-09 00:06:12 +08:00
|
|
|
parser.add_argument('-u', '--update',
|
2020-10-27 22:01:00 +08:00
|
|
|
help="Update versions file from tree.")
|
2020-07-09 00:06:12 +08:00
|
|
|
parser.add_argument('-L', '--latest', action="store_true",
|
2020-10-27 22:01:00 +08:00
|
|
|
help="Get latest published version")
|
|
|
|
parser.add_argument('-w', '--weekly', action="store_true",
|
|
|
|
help="Mark as weekly")
|
2020-12-17 23:05:12 +08:00
|
|
|
parser.add_argument('-v', '--verbose', action="store_true",
|
|
|
|
help="Verbose output")
|
2020-07-09 00:06:12 +08:00
|
|
|
return parser.parse_args()
|
|
|
|
|
2020-10-27 22:01:00 +08:00
|
|
|
|
2020-07-09 00:06:12 +08:00
|
|
|
def get_versions():
|
|
|
|
data = None
|
2020-10-27 22:01:00 +08:00
|
|
|
if not os.path.exists('versions.json'):
|
|
|
|
url = 'https://testing.zephyrproject.org/daily_tests/versions.json'
|
|
|
|
urllib.request.urlretrieve(url, 'versions.json')
|
2020-07-09 00:06:12 +08:00
|
|
|
with open("versions.json", "r") as fp:
|
|
|
|
data = json.load(fp)
|
|
|
|
|
|
|
|
return data
|
|
|
|
|
2020-10-27 22:01:00 +08:00
|
|
|
def handle_compat(item):
|
|
|
|
item_compat = {}
|
|
|
|
if isinstance(item, str):
|
|
|
|
item_compat['version'] = item
|
|
|
|
item_compat['weekly'] = False
|
|
|
|
item_compat['date'] = None
|
|
|
|
else:
|
|
|
|
item_compat = item
|
|
|
|
|
|
|
|
return item_compat
|
|
|
|
|
2020-07-09 00:06:12 +08:00
|
|
|
def show_versions():
|
|
|
|
data = get_versions()
|
2020-10-27 22:01:00 +08:00
|
|
|
for item in data:
|
|
|
|
item_compat = handle_compat(item)
|
|
|
|
is_weekly = item_compat.get('weekly', False)
|
|
|
|
wstr = ""
|
|
|
|
datestr = ""
|
2020-12-17 23:05:12 +08:00
|
|
|
if args.verbose:
|
|
|
|
if is_weekly:
|
|
|
|
wstr = "(marked for weekly testing)"
|
|
|
|
if item_compat.get('date'):
|
|
|
|
pdate = datetime.strptime(item_compat['date'], '%Y-%m-%dT%H:%M:%S.%f')
|
|
|
|
date = pdate.strftime("%b %d %Y %H:%M:%S")
|
|
|
|
datestr = f"published on {date}"
|
|
|
|
print(f"- {item_compat['version']} {datestr} {wstr}")
|
|
|
|
else:
|
|
|
|
print(f"{item_compat['version']}")
|
2020-10-27 22:01:00 +08:00
|
|
|
|
2020-07-09 00:06:12 +08:00
|
|
|
|
|
|
|
def show_latest():
|
|
|
|
data = get_versions()
|
2020-10-27 22:01:00 +08:00
|
|
|
latest = data[-1]
|
|
|
|
item_compat = handle_compat(latest)
|
|
|
|
|
|
|
|
ver = item_compat.get("version")
|
|
|
|
date = item_compat.get("date", False)
|
|
|
|
is_weekly = item_compat.get('weekly')
|
|
|
|
datestr = ""
|
|
|
|
if date:
|
|
|
|
datestr = f"published on {date}"
|
2020-12-17 23:05:12 +08:00
|
|
|
if args.verbose:
|
|
|
|
print(f"Latest version is {ver} {datestr}")
|
|
|
|
if args.verbose and is_weekly:
|
2020-10-27 22:01:00 +08:00
|
|
|
print("This version is marked for weekly testing.")
|
|
|
|
|
2020-12-17 23:05:12 +08:00
|
|
|
if not args.verbose:
|
|
|
|
print(f"{ver}")
|
|
|
|
|
2020-07-09 00:06:12 +08:00
|
|
|
|
2020-10-27 22:01:00 +08:00
|
|
|
def update(git_tree, is_weekly=False):
|
2020-07-09 00:06:12 +08:00
|
|
|
g = Git(git_tree)
|
2020-10-27 22:01:00 +08:00
|
|
|
today = datetime.now().strftime('%Y-%m-%dT%H:%M:%S.%f')
|
2021-01-07 16:31:16 +08:00
|
|
|
version = g.describe("--abbrev=12")
|
2020-07-09 00:06:12 +08:00
|
|
|
published = False
|
|
|
|
data = get_versions()
|
2020-10-27 22:01:00 +08:00
|
|
|
|
2020-12-17 23:05:12 +08:00
|
|
|
if not is_weekly:
|
|
|
|
wday = datetime.today().strftime('%A')
|
|
|
|
if wday == 'Monday':
|
|
|
|
is_weekly = True
|
|
|
|
|
2020-10-27 22:01:00 +08:00
|
|
|
found = list(filter(lambda item: (isinstance(item, dict) and
|
|
|
|
item.get('version') == version) or item == version, data))
|
|
|
|
if found:
|
2020-07-09 00:06:12 +08:00
|
|
|
published = True
|
|
|
|
print("version already published")
|
|
|
|
else:
|
|
|
|
print(f"New version {version}, adding to file...")
|
|
|
|
|
|
|
|
if data and not published:
|
|
|
|
with open(VERSIONS_FILE, "w") as versions:
|
2020-10-27 22:01:00 +08:00
|
|
|
item = {}
|
|
|
|
item['version'] = version
|
|
|
|
item['date'] = today
|
|
|
|
item['weekly'] = is_weekly
|
|
|
|
data.append(item)
|
2020-07-09 00:06:12 +08:00
|
|
|
json.dump(data, versions)
|
|
|
|
|
|
|
|
def main():
|
2020-12-17 23:05:12 +08:00
|
|
|
global args
|
|
|
|
|
2020-07-09 00:06:12 +08:00
|
|
|
args = parse_args()
|
|
|
|
if args.update:
|
2020-10-27 22:01:00 +08:00
|
|
|
update(args.update, args.weekly)
|
2020-07-09 00:06:12 +08:00
|
|
|
elif args.list:
|
|
|
|
show_versions()
|
|
|
|
elif args.latest:
|
|
|
|
show_latest()
|
2020-10-27 22:01:00 +08:00
|
|
|
else:
|
|
|
|
print("You did not specify any options")
|
2020-07-09 00:06:12 +08:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|