quick mode - skip thumbnail generation if files already exist
This commit is contained in:
parent
217950eeaf
commit
ad3ced80df
3 changed files with 79 additions and 66 deletions
|
@ -31,11 +31,76 @@ def main() -> None:
|
||||||
case "init":
|
case "init":
|
||||||
cmd_init(args)
|
cmd_init(args)
|
||||||
case "generate":
|
case "generate":
|
||||||
|
if args.quick:
|
||||||
|
config.quick = args.quick
|
||||||
cmd_generate(args, config)
|
cmd_generate(args, config)
|
||||||
case "clean":
|
case "clean":
|
||||||
cmd_clean(args, config)
|
cmd_clean(args, config)
|
||||||
|
|
||||||
|
|
||||||
|
def parse_args() -> Namespace:
|
||||||
|
parser = ArgumentParser()
|
||||||
|
parser.add_argument(
|
||||||
|
"--config",
|
||||||
|
"-c",
|
||||||
|
default=DEFAULT_CONFIG_PATH,
|
||||||
|
help="Path to photoalbum.config.json for the album",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--logging",
|
||||||
|
default="warning",
|
||||||
|
choices=[level.lower() for level in logging.getLevelNamesMapping().keys()],
|
||||||
|
help="Log level",
|
||||||
|
)
|
||||||
|
|
||||||
|
subcommands = parser.add_subparsers(title="subcommands")
|
||||||
|
|
||||||
|
init_cmd = subcommands.add_parser(
|
||||||
|
"init",
|
||||||
|
help="Initialize an photo directory",
|
||||||
|
)
|
||||||
|
init_cmd.set_defaults(action="init")
|
||||||
|
init_cmd.add_argument(
|
||||||
|
"album_path",
|
||||||
|
nargs="?",
|
||||||
|
default=".",
|
||||||
|
help="Path to the main photos directory",
|
||||||
|
)
|
||||||
|
|
||||||
|
# Generate subcommand
|
||||||
|
generate_cmd = subcommands.add_parser(
|
||||||
|
"generate",
|
||||||
|
help="Generate the HTML photo album",
|
||||||
|
)
|
||||||
|
generate_cmd.set_defaults(action="generate")
|
||||||
|
generate_cmd.add_argument(
|
||||||
|
"--quick",
|
||||||
|
action="store_true",
|
||||||
|
help="Quick mode - don't regenerate thumbnails",
|
||||||
|
)
|
||||||
|
generate_cmd.add_argument(
|
||||||
|
"album_path",
|
||||||
|
nargs="?",
|
||||||
|
default=".",
|
||||||
|
help="Path to the main photos directory",
|
||||||
|
)
|
||||||
|
|
||||||
|
# Clean subcommand
|
||||||
|
clean_cmd = subcommands.add_parser(
|
||||||
|
"clean",
|
||||||
|
help="Remove all generated content from the photo album directory",
|
||||||
|
)
|
||||||
|
clean_cmd.set_defaults(action="clean")
|
||||||
|
clean_cmd.add_argument(
|
||||||
|
"album_path",
|
||||||
|
nargs="?",
|
||||||
|
default=".",
|
||||||
|
help="Path to the main photos directory",
|
||||||
|
)
|
||||||
|
|
||||||
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
########################################
|
########################################
|
||||||
# Command functions
|
# Command functions
|
||||||
def cmd_init(args: Namespace) -> None:
|
def cmd_init(args: Namespace) -> None:
|
||||||
|
@ -86,64 +151,6 @@ def cmd_clean(args: Namespace, config: Config) -> None:
|
||||||
|
|
||||||
########################################
|
########################################
|
||||||
# CLI Util functions
|
# CLI Util functions
|
||||||
def parse_args() -> Namespace:
|
|
||||||
parser = ArgumentParser()
|
|
||||||
parser.add_argument(
|
|
||||||
"--config",
|
|
||||||
"-c",
|
|
||||||
default=DEFAULT_CONFIG_PATH,
|
|
||||||
help="Path to photoalbum.config.json for the album",
|
|
||||||
)
|
|
||||||
parser.add_argument(
|
|
||||||
"--logging",
|
|
||||||
default="warning",
|
|
||||||
choices=[level.lower() for level in logging.getLevelNamesMapping().keys()],
|
|
||||||
help="Log level",
|
|
||||||
)
|
|
||||||
|
|
||||||
subcommands = parser.add_subparsers(title="subcommands")
|
|
||||||
|
|
||||||
init_cmd = subcommands.add_parser(
|
|
||||||
"init",
|
|
||||||
help="Initialize an photo directory",
|
|
||||||
)
|
|
||||||
init_cmd.set_defaults(action="init")
|
|
||||||
init_cmd.add_argument(
|
|
||||||
"album_path",
|
|
||||||
nargs="?",
|
|
||||||
default=".",
|
|
||||||
help="Path to the main photos directory",
|
|
||||||
)
|
|
||||||
|
|
||||||
# Generate subcommand
|
|
||||||
generate_cmd = subcommands.add_parser(
|
|
||||||
"generate",
|
|
||||||
help="Generate the HTML photo album",
|
|
||||||
)
|
|
||||||
generate_cmd.set_defaults(action="generate")
|
|
||||||
generate_cmd.add_argument(
|
|
||||||
"album_path",
|
|
||||||
nargs="?",
|
|
||||||
default=".",
|
|
||||||
help="Path to the main photos directory",
|
|
||||||
)
|
|
||||||
|
|
||||||
# Clean subcommand
|
|
||||||
clean_cmd = subcommands.add_parser(
|
|
||||||
"clean",
|
|
||||||
help="Remove all generated content from the photo album directory",
|
|
||||||
)
|
|
||||||
clean_cmd.set_defaults(action="clean")
|
|
||||||
clean_cmd.add_argument(
|
|
||||||
"album_path",
|
|
||||||
nargs="?",
|
|
||||||
default=".",
|
|
||||||
help="Path to the main photos directory",
|
|
||||||
)
|
|
||||||
|
|
||||||
return parser.parse_args()
|
|
||||||
|
|
||||||
|
|
||||||
def setup_logging(level_str: str) -> None:
|
def setup_logging(level_str: str) -> None:
|
||||||
levels = logging.getLevelNamesMapping()
|
levels = logging.getLevelNamesMapping()
|
||||||
level = levels[level_str.upper()]
|
level = levels[level_str.upper()]
|
||||||
|
|
|
@ -16,6 +16,10 @@ class Config:
|
||||||
# Size of the image when looking at the standalone image page
|
# Size of the image when looking at the standalone image page
|
||||||
view_size: tuple[int, int] = (1920, 1080)
|
view_size: tuple[int, int] = (1920, 1080)
|
||||||
|
|
||||||
|
# Quick mode:
|
||||||
|
# - Don't regenerate thumbnails if they already exist
|
||||||
|
quick: bool = False
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_yaml(cls, contents: bytes) -> "Config":
|
def from_yaml(cls, contents: bytes) -> "Config":
|
||||||
conf = cls()
|
conf = cls()
|
||||||
|
|
|
@ -149,15 +149,17 @@ def generate_thumbnails(config: Config, root_dir: ImageDirectory) -> None:
|
||||||
slides_path = image_path.path.parent / "slides"
|
slides_path = image_path.path.parent / "slides"
|
||||||
slides_path.mkdir(exist_ok=True)
|
slides_path.mkdir(exist_ok=True)
|
||||||
|
|
||||||
|
thumb_path = image_path.thumbnail_path()
|
||||||
|
if not thumb_path.exists() or not config.quick:
|
||||||
thumb_img = orig_img.copy()
|
thumb_img = orig_img.copy()
|
||||||
thumb_img.thumbnail(config.thumbnail_size)
|
thumb_img.thumbnail(config.thumbnail_size)
|
||||||
thumb_path = image_path.thumbnail_path()
|
|
||||||
thumb_img.save(thumb_path)
|
thumb_img.save(thumb_path)
|
||||||
logger.info(f'Generated thumbnail size "{image_path.path}" -> "{thumb_path}"')
|
logger.info(f'Generated thumbnail size "{image_path.path}" -> "{thumb_path}"')
|
||||||
|
|
||||||
|
screen_path = image_path.display_path()
|
||||||
|
if not screen_path.exists() or not config.quick:
|
||||||
screen_img = orig_img.copy()
|
screen_img = orig_img.copy()
|
||||||
screen_img.thumbnail(config.view_size)
|
screen_img.thumbnail(config.view_size)
|
||||||
screen_path = image_path.display_path()
|
|
||||||
screen_img.save(screen_path)
|
screen_img.save(screen_path)
|
||||||
logger.info(f'Generated screen size "{image_path.path}" -> "{screen_path}"')
|
logger.info(f'Generated screen size "{image_path.path}" -> "{screen_path}"')
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue