6f0cf4521b
- Introduced `source_to_update` parameter to selectively regenerate specific sources. - Updated documentation to reflect new behavior for `clean_first` and `source_to_update`. - Modified CLI and legacy CLI to handle source overrides appropriately.
101 lines
3.0 KiB
Python
101 lines
3.0 KiB
Python
"""
|
|
Scientific Gallery Generator - Legacy CLI Entry Point
|
|
|
|
This module provides backward compatibility for the legacy CLI interface.
|
|
For new development, use the gallery package API directly:
|
|
|
|
from gallery import generate, GalleryConfig
|
|
|
|
config = GalleryConfig.from_yaml("config.yaml")
|
|
generate(config, verbose=True)
|
|
|
|
Or use the new CLI:
|
|
|
|
gallery --config config.yaml --verbose
|
|
"""
|
|
|
|
from gallery import generate
|
|
from gallery.config import GalleryConfig
|
|
|
|
|
|
def main(clean_first: bool = False, source_override: str = None) -> None:
|
|
"""
|
|
Main entry point for gallery generation (legacy interface).
|
|
|
|
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.
|
|
"""
|
|
try:
|
|
# Load configuration from config.yaml
|
|
config = GalleryConfig.from_yaml("config.yaml")
|
|
|
|
# Handle source override
|
|
source_to_update = None
|
|
if source_override:
|
|
from pathlib import Path
|
|
from gallery.config import GallerySource
|
|
|
|
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
|
|
source_to_update = GallerySource(
|
|
name=source_name,
|
|
path=source_path
|
|
)
|
|
config.sources.append(source_to_update)
|
|
print(
|
|
f"Source {source_override} not in config. "
|
|
f"Adding temporarily as '{source_name}'"
|
|
)
|
|
else:
|
|
source_to_update = matching_source
|
|
|
|
# Generate gallery using the new API
|
|
success = generate(
|
|
config=config,
|
|
clean_first=clean_first,
|
|
verbose=True,
|
|
source_to_update=source_to_update
|
|
)
|
|
|
|
if not success:
|
|
exit(1)
|
|
|
|
except Exception as e:
|
|
print(f"Error: {e}")
|
|
exit(1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import argparse
|
|
|
|
parser = argparse.ArgumentParser(description='Generate gallery')
|
|
parser.add_argument(
|
|
'--clean',
|
|
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, source_override=args.source)
|