From 820b91c4a81cf9a0f58ffa101a5e042471b46d57 Mon Sep 17 00:00:00 2001
From: Anatoli Babenia <anatoli@rainforce.org>
Date: Dec 29 2021 23:47:37 +0000
Subject: [PATCH 1/5] Simplify database filtering logic using `defaultdict`


---

diff --git a/bin/generate-html.py b/bin/generate-html.py
index 2999b72..3cb6def 100755
--- a/bin/generate-html.py
+++ b/bin/generate-html.py
@@ -16,6 +16,7 @@ import argparse
 import glob
 
 from datetime import date
+from collections import defaultdict
 
 from jinja2 import Environment, PackageLoader
 
@@ -138,7 +139,7 @@ def main():
         release_mapping = json.load(raw)
 
     # Group databases files.
-    databases = {}
+    databases = defaultdict(dict)
     db_pattern = re.compile(
         "^(fedora|epel)-([\w|-]+)_(primary|filelists|other).sqlite$"
     )
@@ -148,10 +149,7 @@ def main():
 
         (product, branch, db_type) = db_pattern.findall(db)[0]
         release_branch = "{}-{}".format(product, branch)
-        if release_branch in databases:
-            databases[release_branch][db_type] = db
-        else:
-            databases[release_branch] = {db_type: db}
+        databases[release_branch][db_type] = db
 
     # Build internal package metadata structure / cache.
     # { "src_pkg": { "subpackage": pkg, ... } }

From 5bfd36f9bcc13d60a4a9196fc40e44e0ecfd16bb Mon Sep 17 00:00:00 2001
From: Anatoli Babenia <anatoli@rainforce.org>
Date: Dec 29 2021 23:47:37 +0000
Subject: [PATCH 2/5] Only process releases mentioned in production_version_mapping.json


---

diff --git a/bin/generate-html.py b/bin/generate-html.py
index 3cb6def..f0c2ddd 100755
--- a/bin/generate-html.py
+++ b/bin/generate-html.py
@@ -149,7 +149,8 @@ def main():
 
         (product, branch, db_type) = db_pattern.findall(db)[0]
         release_branch = "{}-{}".format(product, branch)
-        databases[release_branch][db_type] = db
+        if release_branch in release_mapping:
+            databases[release_branch][db_type] = db
 
     # Build internal package metadata structure / cache.
     # { "src_pkg": { "subpackage": pkg, ... } }

From 06aa965067cbaa8adebad60a5f4b29f7f44aed7d Mon Sep 17 00:00:00 2001
From: Anatoli Babenia <anatoli@rainforce.org>
Date: Dec 29 2021 23:47:37 +0000
Subject: [PATCH 3/5] Explain what PDC is


---

diff --git a/bin/fetch-repository-dbs.py b/bin/fetch-repository-dbs.py
index c7968df..94bf8a0 100755
--- a/bin/fetch-repository-dbs.py
+++ b/bin/fetch-repository-dbs.py
@@ -358,7 +358,7 @@ def main():
     args = parser.parse_args()
 
     # Get active releases from PDC.
-    print("Fetching active releases from PDC...")
+    print("Fetching active releases from PDC... https://pdc.fedoraproject.org/")
     r = requests.get(
         "https://pdc.fedoraproject.org/rest_api/v1/product-versions/",
         params={"active": "true"},

From a87775aef467b246d850cd9f6893c5148227c4dc Mon Sep 17 00:00:00 2001
From: Anatoli Babenia <anatoli@rainforce.org>
Date: Dec 29 2021 23:47:37 +0000
Subject: [PATCH 4/5] Iindent product_version_mapping for easy editing


---

diff --git a/bin/get-product-names.py b/bin/get-product-names.py
index 7f0d388..2db4207 100755
--- a/bin/get-product-names.py
+++ b/bin/get-product-names.py
@@ -36,7 +36,7 @@ def get_data(URI, previous_data=None):
 def main():
     final_data = get_data(PDC_URI)
     with open(PRODUCT_VERSION_MAPPING, "w") as outfile:
-        json.dump(final_data, outfile)
+        json.dump(final_data, outfile, indent=2)
 
 
 if __name__ == "__main__":

From 2564b326957fb2ea474fd72bcebb86c6c055dbef Mon Sep 17 00:00:00 2001
From: Anatoli Babenia <anatoli@rainforce.org>
Date: Dec 29 2021 23:47:37 +0000
Subject: [PATCH 5/5] Use FileSystemLoader for locating templates


Fixes this Traceback.

    Traceback (most recent call last):
      File "/home/anatoli/f/fedora-packages-static/bin/generate-html.py", line 552, in <module>
	main()
      File "/home/anatoli/f/fedora-packages-static/bin/generate-html.py", line 127, in main
	loader=PackageLoader("generate-html", TEMPLATE_DIR), autoescape=True
      File "/usr/lib/python3.10/site-packages/jinja2/loaders.py", line 309, in __init__
	raise ValueError(
    ValueError: The 'generate-html' package was not installed in a way that PackageLoader understands.
    make: *** [Makefile:39: html] Error 1

---

diff --git a/bin/generate-html.py b/bin/generate-html.py
index f0c2ddd..d50ac6d 100755
--- a/bin/generate-html.py
+++ b/bin/generate-html.py
@@ -17,10 +17,12 @@ import glob
 
 from datetime import date
 from collections import defaultdict
+from pathlib import Path
 
-from jinja2 import Environment, PackageLoader
+from jinja2 import Environment, FileSystemLoader
 
-TEMPLATE_DIR = "../templates"
+ROOT_DIR = Path(__file__).parent.parent
+TEMPLATE_DIR = ROOT_DIR / "templates"
 DBS_DIR = os.environ.get("DB_DIR") or "repositories"
 ASSETS_DIR = "assets"
 SCM_MAINTAINER_MAPPING = (
@@ -124,7 +126,7 @@ def main():
 
     # Initialize templating system.
     env = Environment(
-        loader=PackageLoader("generate-html", TEMPLATE_DIR), autoescape=True
+        loader=FileSystemLoader(TEMPLATE_DIR), autoescape=True
     )
 
     # Load maintainer mapping (imported from dist-git).

