Album skeleton creation
This commit is contained in:
parent
4e6cf1d499
commit
e3816dfdb7
8 changed files with 85 additions and 29 deletions
|
|
@ -1,26 +1,56 @@
|
|||
import logging
|
||||
from pathlib import Path
|
||||
|
||||
from rich.progress import track
|
||||
from PIL import Image, UnidentifiedImageError
|
||||
from rich.progress import track
|
||||
|
||||
from photoalbum.config import Config
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def generate(config: Config, path: Path) -> None:
|
||||
|
||||
def generate(config: Config, album_path: Path) -> None:
|
||||
"""
|
||||
Main generation function
|
||||
"""
|
||||
skeleton_created = maybe_create_skeleton(config)
|
||||
generate_thumbnails(config, path)
|
||||
generate_html_dir(config, path)
|
||||
skel_files_created, skel_files = maybe_create_skeleton(config, album_path)
|
||||
# generate_thumbnails(config, album_path)
|
||||
# generate_html(config, album_path)
|
||||
|
||||
if skel_files_created:
|
||||
print(
|
||||
"Some basic files have been created for your album. Edit them as you need:"
|
||||
)
|
||||
for p in skel_files:
|
||||
print(f" - {p}")
|
||||
|
||||
|
||||
def maybe_create_skeleton(config: Config) -> bool:
|
||||
def maybe_create_skeleton(config: Config, album_path: Path) -> tuple[bool, list[Path]]:
|
||||
"""
|
||||
Create basic config, template, and static files if they don't already exist in the
|
||||
repo
|
||||
"""
|
||||
return False
|
||||
files_created = False
|
||||
skel_files = []
|
||||
|
||||
skel_dir = Path(__file__).parent / "skel"
|
||||
logging.debug(f"Skeleton dir: {skel_dir}")
|
||||
|
||||
for parent_path, dirnames, filenames in skel_dir.walk():
|
||||
for filename in filenames:
|
||||
skel_file_path = parent_path / filename
|
||||
rel_path = skel_file_path.relative_to(skel_dir)
|
||||
album_file_path = album_path / rel_path
|
||||
|
||||
skel_files.append(album_file_path)
|
||||
|
||||
if not album_file_path.exists():
|
||||
album_file_path.parent.mkdir(exist_ok=True)
|
||||
album_file_path.write_bytes(skel_file_path.read_bytes())
|
||||
logger.debug(f"Created skeleton file {album_file_path}")
|
||||
files_created = True
|
||||
|
||||
return files_created, skel_files
|
||||
|
||||
|
||||
def generate_thumbnails(config: Config, path: Path) -> None:
|
||||
|
|
@ -33,11 +63,11 @@ def generate_thumbnails(config: Config, path: Path) -> None:
|
|||
try:
|
||||
Image.open(parent_path / filename)
|
||||
except UnidentifiedImageError:
|
||||
continue # Not an image file
|
||||
continue # Not an image file
|
||||
|
||||
# If we modify dirnames in-place, walk() will skip anything we remove
|
||||
if 'slides' in dirnames:
|
||||
dirnames.remove('slides')
|
||||
if "slides" in dirnames:
|
||||
dirnames.remove("slides")
|
||||
|
||||
images.append((parent_path, filename))
|
||||
|
||||
|
|
@ -59,7 +89,7 @@ def generate_thumbnails(config: Config, path: Path) -> None:
|
|||
screen_img.save(slides_path / screen_filename)
|
||||
|
||||
|
||||
def generate_html_dir(config: Config, path: Path) -> None:
|
||||
def generate_html(config: Config, path: Path) -> None:
|
||||
"""
|
||||
Recursively generate HTML files for this directory and all children
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue