Use voussoirkit.gentools for chunk_generator.

This commit is contained in:
voussoir 2020-11-15 22:10:21 -08:00
parent 7d454a03ac
commit 9ca40c6ae7
2 changed files with 2 additions and 19 deletions

View file

@ -149,24 +149,6 @@ def checkerboard_image(color_1, color_2, image_size, checker_size):
offset = not offset
return image
def chunk_sequence(sequence, chunk_length, allow_incomplete=True):
'''
Given a sequence, yield lists of length `chunk_length`.
allow_incomplete:
If True, allow the final chunk to be shorter if the
given sequence is not an exact multiple of `chunk_length`.
If False, the incomplete chunk will be discarded.
'''
import itertools
iterator = iter(sequence)
while True:
chunk = list(itertools.islice(iterator, chunk_length))
if not chunk:
break
if len(chunk) == chunk_length or allow_incomplete:
yield chunk
def collapse_whitespace(s):
s = s.strip()
s = re.sub(r'\s+', ' ', s)

View file

@ -10,6 +10,7 @@ import send2trash
import traceback
from voussoirkit import bytestring
from voussoirkit import gentools
from voussoirkit import hms
from voussoirkit import pathclass
from voussoirkit import sentinel
@ -961,7 +962,7 @@ class Photo(ObjectBase):
'''
Create the filepath that should be the location of our thumbnail.
'''
chunked_id = [''.join(chunk) for chunk in helpers.chunk_sequence(self.id, 3)]
chunked_id = [''.join(chunk) for chunk in gentools.chunk_generator(self.id, 3)]
(folder, basename) = (chunked_id[:-1], chunked_id[-1])
folder = os.sep.join(folder)
folder = self.photodb.thumbnail_directory.join(folder)