-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor product filtering and loading for generic scripts
Create a common function to list and load product configurations for generic scripts. Generic scripts are scripts that handle multiple product based on some identifier (URL, coordinates...). This make them more simple to read and maintain, while making the way they work much more consistent. This is only the first step in that process, the end goal being: - providing utilities to simplify the maintenance of existing scripts / development of new scripts (while keeping those script independent), - being able to change globaly how things work (such as #51)
- Loading branch information
1 parent
3b40b72
commit aa4aa8f
Showing
7 changed files
with
97 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ website | |
vendor | ||
.bundle | ||
pyrightconfig.json | ||
__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters