Added tests, better naming, address comments

This commit is contained in:
Sean Grider
2023-06-05 10:38:27 -04:00
parent 384affd891
commit f0f224f8c0
3 changed files with 24 additions and 17 deletions

View File

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

View File

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

View File

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