Add override for new directory from the CLI
This commit is contained in:
+40
-4
@@ -19,7 +19,7 @@ from typing import Dict, Any, Optional
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from jinja2 import Environment, FileSystemLoader
|
from jinja2 import Environment, FileSystemLoader
|
||||||
|
|
||||||
from utils.config import Config
|
from utils.config import Config, GalleryItem
|
||||||
from utils.metadata import (
|
from utils.metadata import (
|
||||||
load_folder_metadata,
|
load_folder_metadata,
|
||||||
merge_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.
|
Main entry point for gallery generation.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
clean_first: If True, removes and recreates the gallery directory
|
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
|
Processes all configured sources and generates the complete gallery
|
||||||
structure in the web directory. Ensures assets are available.
|
structure in the web directory. Ensures assets are available.
|
||||||
@@ -151,9 +155,34 @@ def main(clean_first: bool = False) -> None:
|
|||||||
else:
|
else:
|
||||||
print(f"Warning: Assets directory {assets_src} not found")
|
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 = []
|
source_subdirs = []
|
||||||
|
|
||||||
for source in CONFIG.sources:
|
for source in sources_to_process:
|
||||||
source_path = Path(source.path)
|
source_path = Path(source.path)
|
||||||
source_web_dir = gallery_root / source.name
|
source_web_dir = gallery_root / source.name
|
||||||
source_web_dir.mkdir(parents=True, exist_ok=True)
|
source_web_dir.mkdir(parents=True, exist_ok=True)
|
||||||
@@ -203,5 +232,12 @@ if __name__ == "__main__":
|
|||||||
action='store_true',
|
action='store_true',
|
||||||
help='Clean gallery directory before generation'
|
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()
|
args = parser.parse_args()
|
||||||
main(clean_first=args.clean)
|
main(clean_first=args.clean, source_override=args.source)
|
||||||
|
|||||||
Reference in New Issue
Block a user