automatically set default_version
authorPaul Spooren <mail@aparcar.org>
Wed, 7 Oct 2020 21:11:39 +0000 (11:11 -1000)
committerPaul Spooren <mail@aparcar.org>
Thu, 8 Oct 2020 09:28:48 +0000 (23:28 -1000)
This compares activated numeric versions and selects the latest one. Non
numeric versions are skipped, e.g. snapshots.

Signed-off-by: Paul Spooren <mail@aparcar.org>
misc/collect.py

index 95a1c3914c3275710ea4f6ab7089a64fa829ba81..c31adcd547f729628aea0f0314fce735d58721ae 100755 (executable)
@@ -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: