From 7e36688d1dc759f258fab3811a7aa5cc8dc73667 Mon Sep 17 00:00:00 2001 From: Kylian Schmidt Date: Wed, 22 Apr 2026 13:16:08 +0200 Subject: [PATCH] Add override for new directory from the CLI --- generate_gallery.py | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/generate_gallery.py b/generate_gallery.py index 9423e89..10d99d6 100644 --- a/generate_gallery.py +++ b/generate_gallery.py @@ -19,7 +19,7 @@ from typing import Dict, Any, Optional from datetime import datetime from jinja2 import Environment, FileSystemLoader -from utils.config import Config +from utils.config import Config, GalleryItem from utils.metadata import ( load_folder_metadata, merge_metadata, @@ -120,12 +120,16 @@ def build_gallery( ) -def main(clean_first: bool = False) -> None: +def main( + clean_first: bool = False, source_override: Optional[str] = None +) -> None: """ Main entry point for gallery generation. Args: clean_first: If True, removes and recreates the gallery directory + source_override: If provided, only process this source directory. + If not in config, it will be temporarily added. Processes all configured sources and generates the complete gallery structure in the web directory. Ensures assets are available. @@ -151,9 +155,34 @@ def main(clean_first: bool = False) -> None: else: print(f"Warning: Assets directory {assets_src} not found") + # Determine which sources to process + if source_override: + source_path = Path(source_override).resolve() + + # Check if source is in config + matching_source = None + for source in CONFIG.sources: + if Path(source.path).resolve() == source_path: + matching_source = source + break + + # If not in config, create a temporary source entry + if matching_source is None: + source_name = source_path.name + msg = ( + f"Source {source_override} not in config. " + f"Adding temporarily as '{source_name}'" + ) + print(msg) + matching_source = GalleryItem(name=source_name, path=source_path) + + sources_to_process = [matching_source] + else: + sources_to_process = CONFIG.sources + source_subdirs = [] - for source in CONFIG.sources: + for source in sources_to_process: source_path = Path(source.path) source_web_dir = gallery_root / source.name source_web_dir.mkdir(parents=True, exist_ok=True) @@ -203,5 +232,12 @@ if __name__ == "__main__": action='store_true', help='Clean gallery directory before generation' ) + parser.add_argument( + '--source', + type=str, + default=None, + help='Override to only recompute a specific source directory. ' + 'If the directory is not in config, it will be added temporarily.' + ) args = parser.parse_args() - main(clean_first=args.clean) + main(clean_first=args.clean, source_override=args.source)