diff --git a/src/sigal/gallery.py b/src/sigal/gallery.py index bb319c7..d06108d 100644 --- a/src/sigal/gallery.py +++ b/src/sigal/gallery.py @@ -56,6 +56,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 @@ -824,7 +825,7 @@ class Gallery: for subname, album in self.get_albums(subdir): yield subname, self.albums[subdir] - def build(self, force=None): + def build(self, force=False): "Create the image gallery" if not self.albums: @@ -936,23 +937,8 @@ 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 forcing(album): + if isfile(f.dst_path) and not should_reprocess_album(a.path, a.name, force): self.logger.info("%s exists - skipping", f.dst_filename) self.stats[f.type + "_skipped"] += 1 else: diff --git a/src/sigal/utils.py b/src/sigal/utils.py index 851b929..7adf205 100644 --- a/src/sigal/utils.py +++ b/src/sigal/utils.py @@ -81,6 +81,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 diff --git a/tests/test_utils.py b/tests/test_utils.py index b47f709..973ab99 100644 --- a/tests/test_utils.py +++ b/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 should_reprocess_album('Gallery/New Pics', 'New Pics', False) is False + assert should_reprocess_album('Gallery/New Pics', 'New Pics', True) is True + assert should_reprocess_album('Gallery/New Pics', 'New Pics', ['Gallery/*']) is True + assert should_reprocess_album('Gallery/New Pics', 'New Pics', ['Gallery/*Pics']) is True + assert should_reprocess_album('Gallery/New Pics', 'New Pics', ['Pictures/*']) is False + assert should_reprocess_album('Gallery/New Pics', 'New Pics', ['New Pics']) is True + assert should_reprocess_album('Gallery/New Pics', 'New Pics', ['Pictures']) is False + assert should_reprocess_album('Gallery/New Pics', 'New Pics', ['Pictures', 'Something']) is False + assert 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"))