aboutsummaryrefslogtreecommitdiff
path: root/generate-gallery.py
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2026-03-14 11:33:09 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2026-03-14 11:33:09 +0100
commit833e687e2950fb89d9a26d0f060d57bb8bd12574 (patch)
treeccc03d77ba1cee95d2287244353033502f7472c9 /generate-gallery.py
parent3cc7196d40d34be8f994bd37b8bf7a7ac6902b7f (diff)
downloadscratch-gallery-main.tar.gz
scratch-gallery-main.zip
remove empty directories from the project tableHEADmain
Diffstat (limited to 'generate-gallery.py')
-rwxr-xr-xgenerate-gallery.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/generate-gallery.py b/generate-gallery.py
index 375adbd..8ddc0c0 100755
--- a/generate-gallery.py
+++ b/generate-gallery.py
@@ -43,6 +43,14 @@ def nested_set(data_dict, key_sequence, value):
data_dict = data_dict.setdefault(key, {})
data_dict[key_sequence[-1]] = value
+def nested_clean(d):
+ """Recursivly remove empty nested dict values from a dict"""
+ items = list(d.items())
+ for key, value in items:
+ if isinstance(value, dict):
+ nested_clean(value)
+ if len(value) == 0:
+ del d[key]
def load_projects(root: str, publishable=False) -> dict:
"""Load all game meta data from the games directory"""
@@ -86,6 +94,11 @@ def load_projects(root: str, publishable=False) -> dict:
nested_set(projects, parent.parts[1:], game)
+ ## Cleanup
+ # Remove empty directories from the project table
+ nested_clean(projects)
+
+ # Remove the test project if there are other real projects
if len(projects) > 1:
del projects['test']