Skip to content

Commit

Permalink
Added support for -a, --force-album argument
Browse files Browse the repository at this point in the history
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'
  • Loading branch information
KaibutsuX committed Jun 2, 2023
1 parent 0923a56 commit d82b376
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
18 changes: 16 additions & 2 deletions docs/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Build
a sub-directory and run ``sigal build <your images directory>``.

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.

Expand All @@ -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:
Expand All @@ -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

Expand Down
5 changes: 3 additions & 2 deletions src/sigal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,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",
Expand Down Expand Up @@ -109,7 +110,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.
Expand Down Expand Up @@ -171,7 +172,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"]:
Expand Down
20 changes: 18 additions & 2 deletions src/sigal/gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
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
Expand Down Expand Up @@ -823,7 +824,7 @@ def get_albums(self, path):
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:
Expand Down Expand Up @@ -935,8 +936,23 @@ def remove_files(self, medias):

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:
Expand Down

0 comments on commit d82b376

Please sign in to comment.