Skip to content

Commit

Permalink
Merge pull request #491 from KaibutsuX/supportAlbumForce
Browse files Browse the repository at this point in the history
Added support for -a, --force-album argument
  • Loading branch information
saimn committed Jul 5, 2023
2 parents b45d018 + 81c0d81 commit 2dc1e55
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 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/Pictures => 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 @@ -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",
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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"]:
Expand Down
3 changes: 2 additions & 1 deletion src/sigal/gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
is_valid_html5_video,
read_markdown,
url_from_path,
should_reprocess_album,
)
from .video import process_video
from .writer import AlbumListPageWriter, AlbumPageWriter
Expand Down Expand Up @@ -936,7 +937,7 @@ def remove_files(self, medias):
def process_dir(self, album, force=False):
"""Process a list of images in a directory."""
for f in album:
if isfile(f.dst_path) and not force:
if isfile(f.dst_path) and not should_reprocess_album(album.path, album.name, force):
self.logger.info("%s exists - skipping", f.dst_filename)
self.stats[f.type + "_skipped"] += 1
else:
Expand Down
12 changes: 12 additions & 0 deletions src/sigal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import shutil
from functools import lru_cache
from urllib.parse import quote
from fnmatch import fnmatch

from markdown import Markdown
from markupsafe import Markup
Expand Down Expand Up @@ -81,6 +82,17 @@ def url_from_path(path):
path = "/".join(path.split(os.sep))
return quote(path)

def should_reprocess_album(path, name, force=False):
if isinstance(force, bool):
return force
else:
for f in force:
if '*' in f or '?' in f:
if fnmatch(path, f):
return True
elif name == f:
return True
return False

def read_markdown(filename):
"""Reads markdown file, converts output and fetches title and meta-data for
Expand Down
10 changes: 10 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ def test_copy(tmpdir):
utils.copy(src, dst)
utils.copy(src, dst)

def test_force(tmpdir):
assert utils.should_reprocess_album('Gallery/New Pics', 'New Pics', False) is False
assert utils.should_reprocess_album('Gallery/New Pics', 'New Pics', True) is True
assert utils.should_reprocess_album('Gallery/New Pics', 'New Pics', ['Gallery/*']) is True
assert utils.should_reprocess_album('Gallery/New Pics', 'New Pics', ['Gallery/*Pics']) is True
assert utils.should_reprocess_album('Gallery/New Pics', 'New Pics', ['Pictures/*']) is False
assert utils.should_reprocess_album('Gallery/New Pics', 'New Pics', ['New Pics']) is True
assert utils.should_reprocess_album('Gallery/New Pics', 'New Pics', ['Pictures']) is False
assert utils.should_reprocess_album('Gallery/New Pics', 'New Pics', ['Pictures', 'Something']) is False
assert utils.should_reprocess_album('Gallery/New Pics', 'New Pics', ['Pictures', 'Gallery', '*Pics']) is True

def test_check_or_create_dir(tmpdir):
path = str(tmpdir.join("new_directory"))
Expand Down

0 comments on commit 2dc1e55

Please sign in to comment.