From: Paul Spooren Date: Wed, 7 Oct 2020 21:11:39 +0000 (-1000) Subject: automatically set default_version X-Git-Tag: v3.0.4~1 X-Git-Url: http://git.openwrt.org/?a=commitdiff_plain;h=6ffcc312897f65ae3532b404646acd25afbba4f3;p=web%2Ffirmware-selector-openwrt-org.git 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 --- 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: