Browse Source

Added tests, better naming, address comments

pull/491/head
Sean Grider 3 years ago
parent
commit
f0f224f8c0
  1. 20
      src/sigal/gallery.py
  2. 11
      src/sigal/utils.py
  3. 10
      tests/test_utils.py

20
src/sigal/gallery.py

@ -56,6 +56,7 @@ from .utils import (
is_valid_html5_video, is_valid_html5_video,
read_markdown, read_markdown,
url_from_path, url_from_path,
should_reprocess_album,
) )
from .video import process_video from .video import process_video
from .writer import AlbumListPageWriter, AlbumPageWriter from .writer import AlbumListPageWriter, AlbumPageWriter
@ -824,7 +825,7 @@ class Gallery:
for subname, album in self.get_albums(subdir): for subname, album in self.get_albums(subdir):
yield subname, self.albums[subdir] yield subname, self.albums[subdir]
def build(self, force=None): def build(self, force=False):
"Create the image gallery" "Create the image gallery"
if not self.albums: if not self.albums:
@ -936,23 +937,8 @@ class Gallery:
def process_dir(self, album, force=False): def process_dir(self, album, force=False):
"""Process a list of images in a directory.""" """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: 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.logger.info("%s exists - skipping", f.dst_filename)
self.stats[f.type + "_skipped"] += 1 self.stats[f.type + "_skipped"] += 1
else: else:

11
src/sigal/utils.py

@ -81,6 +81,17 @@ def url_from_path(path):
path = "/".join(path.split(os.sep)) path = "/".join(path.split(os.sep))
return quote(path) 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): def read_markdown(filename):
"""Reads markdown file, converts output and fetches title and meta-data for """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)
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): def test_check_or_create_dir(tmpdir):
path = str(tmpdir.join("new_directory")) path = str(tmpdir.join("new_directory"))

Loading…
Cancel
Save