From 4755ec3c1b027081a033175d354c3f9a386c4526 Mon Sep 17 00:00:00 2001 From: Nekkowe Date: Tue, 14 Jan 2025 16:42:35 +0100 Subject: [PATCH] script waits for enter press before exiting, HTML file exists as example from the start / does not get overwritten by script, blacklisting hidden files from csv table, blacklisting gitkeep and gitignore from git archive generation --- .gitattributes | 2 ++ .gitignore | 1 + 1-generate-thumbnails-and-table.py | 24 +++++++++++++++++++ 2-generate-gallery.py | 38 +++++------------------------- gallery/index.html | 29 +++++++++++++++++++++++ 5 files changed, 62 insertions(+), 32 deletions(-) create mode 100644 .gitattributes create mode 100644 gallery/index.html diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..10833f9 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +/**/.gitkeep export-ignore +/**/.gitignore export-ignore \ No newline at end of file diff --git a/.gitignore b/.gitignore index 7f1918d..74384d8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ gallery/** !gallery/**/ !gallery/**/.gitkeep +!gallery/index.html gallery-items*.csv __pycache__ diff --git a/1-generate-thumbnails-and-table.py b/1-generate-thumbnails-and-table.py index 43d4b93..1ba2b85 100644 --- a/1-generate-thumbnails-and-table.py +++ b/1-generate-thumbnails-and-table.py @@ -12,6 +12,17 @@ THUMBNAIL_FOLDER = Path(__file__, "..", "gallery", "thumbs").resolve() THUMBNAIL_SUFFIX = "-thumb.webp" THUMBNAIL_MAX_FRAMES = 0 # No limit. Feel free to adjust this if you're hosting long animations on there or something. +FILE_BLACKLIST = [ + # Dot files (e.g. .gitkeep, .gitignore, .DS_Store) are ignored by default. + # Windows does not do us the courtesy of having all hidden files start with a period, + # so I'm filtering some of the common ones out "by hand". + # It's possible that I'm missing a couple of common ones. + # If your gallery-items.csv winds up with entries for any files that you + # don't want in your gallery, please feel free to expand this list by hand. + "Thumbs.db", # Windows Thumbnail Cache + "Desktop.ini" # Windows Folder Settings +] + def generate_and_register_thumbnail(file_path, thumbnail_path): try: generate_thumbnail(file_path, thumbnail_path) @@ -57,6 +68,15 @@ def prompt_confirmation(prompt_message): def print_horizontal_separator(): print("--------------") +def is_file_blacklisted(file_name): + if file_name.startswith("."): + return True # Hidden files on Linux and Mac + elif file_name in FILE_BLACKLIST: + return True # Specifically blacklisted + else: + return False # Fine + + if __name__ == "__main__": # Only do this when the script is run directly print("Generating thumbnails...") @@ -72,6 +92,9 @@ if __name__ == "__main__": # Only do this when the script is run directly # for all images discovered in the folder: for file_name in os.listdir(MEDIA_FOLDER): + if is_file_blacklisted(file_name): + continue + print("Checking \"{}\"...".format(file_name)) file_path = Path(MEDIA_FOLDER, file_name).resolve() @@ -159,3 +182,4 @@ if __name__ == "__main__": # Only do this when the script is run directly print("Error writing table:") print("{error_name}: {error}".format(error_name=type(error).__name__, error=error)) + input("Press Enter key to exit...") diff --git a/2-generate-gallery.py b/2-generate-gallery.py index 990932a..3679b9d 100644 --- a/2-generate-gallery.py +++ b/2-generate-gallery.py @@ -4,7 +4,7 @@ from pathlib import Path from lib import GalleryTable -GALLERY_ID = "gallery" # e.g.