From 6ffcc312897f65ae3532b404646acd25afbba4f3 Mon Sep 17 00:00:00 2001 From: Paul Spooren Date: Wed, 7 Oct 2020 11:11:39 -1000 Subject: [PATCH] automatically set default_version This compares activated numeric versions and selects the latest one. Non numeric versions are skipped, e.g. snapshots. Signed-off-by: Paul Spooren --- misc/collect.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/misc/collect.py b/misc/collect.py index 95a1c39..c31adcd 100755 --- a/misc/collect.py +++ b/misc/collect.py @@ -15,6 +15,7 @@ import glob import sys import os import re +from distutils.version import StrictVersion SUPPORTED_METADATA_VERSION = 1 BUILD_DATE_FORMAT = "%Y-%m-%d %H:%M:%S" @@ -126,9 +127,23 @@ def update_config(www_path, versions): with open(str(config_path), "r", encoding="utf-8") as file: content = file.read() + latest_version = "0.0.0" + for version in versions.keys(): + try: + if StrictVersion(version) > StrictVersion(latest_version): + latest_version = version + except ValueError: + print("Non numeric version: {}".format(version)) + continue + content = re.sub( "versions:[\\s]*{[^}]*}", "versions: {}".format(versions), content ) + content = re.sub( + "default_version:.*,", + 'default_version: "{}",'.format(latest_version), + content, + ) with open(str(config_path), "w+") as file: file.write(content) else: -- 2.30.2