Skip to content

Commit

Permalink
Added tests, better naming, address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
KaibutsuX committed Jun 5, 2023
1 parent 60009b7 commit 6ade36c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
20 changes: 3 additions & 17 deletions src/sigal/gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,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 @@ -824,7 +825,7 @@ def get_albums(self, path):
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:
Expand Down Expand Up @@ -936,23 +937,8 @@ def remove_files(self, medias):

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:
Expand Down
11 changes: 11 additions & 0 deletions src/sigal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 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"))
Expand Down

0 comments on commit 6ade36c

Please sign in to comment.