Refactor product filtering and loading for generic scripts

Generic scripts are scripts that handle multiple product based on some identifier (URL, coordinates...).
This creates a common function to list and load product configurations for those scripts.

It makes them simpler to read and maintain, while making the way they work much more consistent.
This commit is contained in:
Marc Wrobel
2023-05-13 14:46:04 +02:00
parent 7c2bddb860
commit 5176abd4d4
7 changed files with 99 additions and 149 deletions

View File

@@ -1,13 +1,11 @@
from glob import glob
import os
import sys
import json
import frontmatter
import urllib.request
import datetime
import re
from common import endoflife
# Major.Minor + Optional Patch, no RC, nightly releases.
METHOD = "maven"
VERSION_REGEX = r'^\d+\.\d+(\.\d+)?$'
@@ -59,37 +57,21 @@ def fetch_releases(package_identifier):
return releases
def update_releases(product_filter=None):
for product_file in glob("website/products/*.md"):
product_name = os.path.splitext(os.path.basename(product_file))[0]
if product_filter and product_name != product_filter:
continue
with open(product_file, "r") as f:
releases = {}
found_maven = False
print("::group::%s" % product_name)
data = frontmatter.load(f)
if "auto" in data:
for config in data["auto"]:
for key, _ in config.items():
if key == "maven":
found_maven = True
releases = releases | fetch_releases(config["maven"])
if found_maven:
write_file(product_name, releases)
print("::endgroup::")
def update_product(product_name, configs):
releases = {}
for config in configs:
releases = releases | fetch_releases(config[METHOD])
def write_file(product_name, releases):
with open("releases/%s.json" % product_name, "w") as f:
with open(f"releases/{product_name}.json", "w") as f:
f.write(json.dumps(dict(
# sort by date then version (desc)
sorted(releases.items(), key=lambda x: (x[1], x[0]), reverse=True)
), indent=2))
if __name__ == "__main__":
if len(sys.argv) > 1:
update_releases(sys.argv[1])
else:
update_releases()
p_filter = sys.argv[1] if len(sys.argv) > 1 else None
for product, configs in endoflife.list_products(METHOD, p_filter).items():
print("::group::%s" % product)
update_product(product, configs)
print("::endgroup::")