From 46ca38d5a42c861d3e84808518b09fc4fa2bb90a Mon Sep 17 00:00:00 2001 From: Sean Grider Date: Fri, 2 Jun 2023 15:40:55 -0400 Subject: [PATCH] Added support for -a, --force-album argument Like --force, but can specify multiple specific album names or wildcard patterns to apply to entire album paths like: -a Pics/* -a *Wedding* -a 'Landscape Photos' --- docs/getting_started.rst | 18 ++++++++++++++++-- src/sigal/__init__.py | 5 +++-- src/sigal/gallery.py | 20 ++++++++++++++++++-- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/docs/getting_started.rst b/docs/getting_started.rst index 83d51c4..71f06a8 100644 --- a/docs/getting_started.rst +++ b/docs/getting_started.rst @@ -18,7 +18,7 @@ Build a sub-directory and run ``sigal build ``. The next time you run ``sigal build``, only the new images will be processed. - You can use the ``-f`` flag to force the reprocessing of all the images. + You can use the ``-f`` flag to force the reprocessing of all the images or the ``-a`` flag to force only the specified matching albums. Images (resp. videos) that are smaller than the size specified by the ``img_size`` (resp. ``video_size``) setting will not be resized. @@ -39,7 +39,7 @@ Help on the ``sigal build`` command :: - $ sigal build [-h] [-d] [-v] [-f] [-c CONFIG] [-t THEME] [-n NCPU] + $ sigal build [-h] [-d] [-v] [-f] [-a PATTERN] [-c CONFIG] [-t THEME] [-n NCPU] [source] [destination] Required arguments: @@ -58,6 +58,20 @@ Optional arguments: ``-f, --force`` Force the reprocessing of existing images and thumbnails +``-a --force-album`` + Force the reprocessing of existing images matching the given album wildcard pattern. + Patterns containing wildcards will be matched against the full album path, while patterns without wildcards will be match against the album name only: + +:: + + -a 'My Pictures/*Pics' + My Pictures/Old Pics => Force + My Pictures/New Pics => Force + My Pictures/My Pics => No Force + -a 'Landscapes' + My Pictures/Landscapes => Force + My Other Pictures/Landscapes => Force + ``-v, --verbose`` Show all messages diff --git a/src/sigal/__init__.py b/src/sigal/__init__.py index a3cb7ee..3c1c6ee 100644 --- a/src/sigal/__init__.py +++ b/src/sigal/__init__.py @@ -78,6 +78,7 @@ def init(path): @argument("source", required=False) @argument("destination", required=False) @option("-f", "--force", is_flag=True, help="Force the reprocessing of existing images") +@option("-a", "--force-album", multiple=True, help="Force reprocessing of any album that matches the given pattern. Patterns containing no wildcards will be matched against only the album name. (-a 'My Pictures/* Pics' -a 'Festival')") @option("-v", "--verbose", is_flag=True, help="Show all messages") @option( "-d", @@ -106,7 +107,7 @@ def init(path): @option("--title", help="Title of the gallery (overrides the title setting.") @option("-n", "--ncpu", help="Number of cpu to use (default: all)") def build( - source, destination, debug, verbose, quiet, force, config, theme, title, ncpu + source, destination, debug, verbose, quiet, force, force_album, config, theme, title, ncpu ): """Run sigal to process a directory. @@ -168,7 +169,7 @@ def build( init_plugins(settings) gal = Gallery(settings, ncpu=ncpu, quiet=quiet) - gal.build(force=force) + gal.build(force=force_album if len(force_album) else force) # copy extra files for src, dst in settings["files_to_copy"]: diff --git a/src/sigal/gallery.py b/src/sigal/gallery.py index daa04a8..bb319c7 100644 --- a/src/sigal/gallery.py +++ b/src/sigal/gallery.py @@ -38,6 +38,7 @@ from itertools import cycle from os.path import isfile, join, splitext from shutil import get_terminal_size from urllib.parse import quote as url_quote +from fnmatch import fnmatch from click import progressbar from natsort import natsort_keygen, ns @@ -823,7 +824,7 @@ class Gallery: for subname, album in self.get_albums(subdir): yield subname, self.albums[subdir] - def build(self, force=False): + def build(self, force=None): "Create the image gallery" if not self.albums: @@ -935,8 +936,23 @@ class Gallery: def process_dir(self, album, force=False): """Process a list of images in a directory.""" + def forcing(a): + if force is None: + return False + if isinstance(force, bool): + return force + elif len(force) == 0: + return True + else: + for f in force: + if '*' in f or '?' in f: + if fnmatch(a.path, f): + return True + elif a.name == f: + return True + for f in album: - if isfile(f.dst_path) and not force: + if isfile(f.dst_path) and not forcing(album): self.logger.info("%s exists - skipping", f.dst_filename) self.stats[f.type + "_skipped"] += 1 else: