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:
27
src/common/endoflife.py
Normal file
27
src/common/endoflife.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import frontmatter
|
||||
|
||||
from glob import glob
|
||||
from os import path
|
||||
|
||||
|
||||
def list_products(method, products_filter=None, pathname = "website/products"):
|
||||
"""Return a list of products that are using the same given update method.
|
||||
"""
|
||||
products_with_method = {}
|
||||
|
||||
for product_file in glob(f"{pathname}/*.md"):
|
||||
product_name = path.splitext(path.basename(product_file))[0]
|
||||
if products_filter and product_name != products_filter:
|
||||
continue
|
||||
|
||||
with open(product_file, "r") as f:
|
||||
data = frontmatter.load(f)
|
||||
if "auto" in data:
|
||||
configs = list(filter(
|
||||
lambda config: method in config.keys(),
|
||||
data["auto"]
|
||||
))
|
||||
if len(configs) > 0:
|
||||
products_with_method[product_name] = configs
|
||||
|
||||
return products_with_method
|
||||
Reference in New Issue
Block a user