Browse Source

Merge pull request #491 from KaibutsuX/supportAlbumForce

Added support for -a, --force-album argument
pull/498/head
Simon Conseil 3 years ago committed by GitHub
parent
commit
2dc1e556b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      docs/getting_started.rst
  2. 5
      src/sigal/__init__.py
  3. 3
      src/sigal/gallery.py
  4. 12
      src/sigal/utils.py
  5. 10
      tests/test_utils.py

18
docs/getting_started.rst

@ -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.
@ -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/Pictures => No Force
-a 'Landscapes'
My Pictures/Landscapes => Force
My Other Pictures/Landscapes => Force
``-v, --verbose``
Show all messages

5
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"]:

3
src/sigal/gallery.py

@ -55,6 +55,7 @@ from .utils import (
is_valid_html5_video,
read_markdown,
url_from_path,
should_reprocess_album,
)
from .video import process_video
from .writer import AlbumListPageWriter, AlbumPageWriter
@ -936,7 +937,7 @@ class Gallery:
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:

12
src/sigal/utils.py

@ -23,6 +23,7 @@ import os
import shutil
from functools import lru_cache
from urllib.parse import quote
from fnmatch import fnmatch
from markdown import Markdown
from markupsafe import Markup
@ -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

10
tests/test_utils.py

@ -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"))

Loading…
Cancel
Save