Skip to content

Commit

Permalink
Be default, build only newly found and missing photos.
Browse files Browse the repository at this point in the history
  • Loading branch information
cbenning committed Jun 27, 2020
1 parent 7902be2 commit dd7986f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
# Include trailing slash
HTTP_ROOT="/"

# Setting to true will force a full rebuild of the gallery photos.
# Setting to false will only generate files which are missing or added
OVERWRITE="false"

# Enable face tag detection.
# Adds a faces button and virtual albums for detected people
PEOPLE_ENABLE="true"
Expand All @@ -44,3 +48,4 @@ RECURSIVE_ALBUMS="true"
# - {parent_album} will be replaced with the parent album
# - {album} will be replaced with the album name
RECURSIVE_ALBUMS_NAME_PATTERN="{parent_album} > {album}"

9 changes: 8 additions & 1 deletion fussel.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@

recursive_albums_name_pattern = os.getenv("RECURSIVE_ALBUMS_NAME_PATTERN")

overwrite = os.getenv("OVERWRITE")
if overwrite == 'true':
overwrite = True
else:
overwrite = False

filenames = [os.path.join(os.path.dirname(os.path.realpath(__file__)), "web", "package.json")]
massedit.edit_files(filenames, ["re.sub(r'^.*\"homepage\":.*$', ' \"homepage\": \""+http_root+"\",', line)"], dry_run=False)

Expand All @@ -62,6 +68,7 @@
watermark_path,
watermark_ratio,
recursive_albums,
recursive_albums_name_pattern
recursive_albums_name_pattern,
overwrite
)
generator.generate_site(output_photos_path, output_data_path, http_root)
32 changes: 21 additions & 11 deletions generator/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
class SiteGenerator:

def __init__(self, site_name, input_photos_dir, people_enabled, watermark_enabled, watermark_path, watermark_ratio,
recursive_albums, recursive_albums_name_pattern):
recursive_albums, recursive_albums_name_pattern, overwrite):
self.input_photos_dir = input_photos_dir
self.people_enabled = people_enabled
self.watermark_enabled = watermark_enabled
self.watermark_path = watermark_path
self.watermark_ratio = watermark_ratio
self.recursive_albums = recursive_albums
self.recursive_albums_name_pattern = recursive_albums_name_pattern
self.overwrite = overwrite
self.people_data = {}
self.albums_data = {}
self.site_data = {
Expand All @@ -28,8 +29,11 @@ def __init__(self, site_name, input_photos_dir, people_enabled, watermark_enable

def process_photo(self, external_path, photo, output_dir):
new_original_photo = os.path.join(output_dir, "original_%s" % os.path.basename(photo))
print(" ----> Copying to '%s'" % new_original_photo)
shutil.copyfile(photo, new_original_photo)

# Only copy if overwrite explicitly asked for or if doesn't exist
if self.overwrite or not os.path.exists(new_original_photo):
print(" ----> Copying to '%s'" % new_original_photo)
shutil.copyfile(photo, new_original_photo)

with Image.open(new_original_photo) as im:
original_size = im.size
Expand All @@ -55,16 +59,21 @@ def process_photo(self, external_path, photo, output_dir):
largest_src = new_sub_photo
if smallest_src is None:
smallest_src = new_sub_photo
print(" ------> Generating photo size... '%s'" % new_sub_photo)
with Image.open(new_original_photo) as im:
im.thumbnail(new_size)
im.save(new_sub_photo)
data['srcSet'] += ["%s/%s %sw" % (external_path, os.path.basename(new_sub_photo), new_size[0])]

# Only generate if overwrite explicitly asked for or if doesn't exist
if self.overwrite or not os.path.exists(new_sub_photo):
print(" ------> Generating photo size... '%s'" % new_sub_photo)
with Image.open(new_original_photo) as im:
im.thumbnail(new_size)
im.save(new_sub_photo)
data['srcSet'] += ["%s/%s %sw" % (external_path, os.path.basename(new_sub_photo), new_size[0])]

data['src'] = "%s/%s" % (external_path, os.path.basename(largest_src))
data['_thumb'] = "%s/%s" % (external_path, os.path.basename(smallest_src))

if self.watermark_enabled:

# Only copy if overwrite explicitly asked for or if doesn't exist
if self.watermark_enabled and (self.overwrite or not os.path.exists(new_original_photo)):
with Image.open(self.watermark_path) as watermark_im:
print(" ------> Adding watermark ... '%s'" % largest_src)
self.apply_watermark(largest_src, watermark_im)
Expand Down Expand Up @@ -276,7 +285,7 @@ def process_album(self, album_dir, album_name, output_albums_photos_path, extern
# TODO externalize this?
external_path = external_root + "static/_gallery/albums/" + album_name_folder
#external_path = external_root + "static/_gallery/albums/" + album_name
os.makedirs(album_folder)
os.makedirs(album_folder, exist_ok=True)

entries = list(map(lambda e: os.path.join(album_dir, e), os.listdir(album_dir)))
dirs = list(filter(lambda e: self.is_supported_album(e), entries))
Expand Down Expand Up @@ -310,7 +319,8 @@ def generate_site(self, output_photos_path, output_data_path, external_root):
output_albums_photos_path = os.path.join(output_photos_path, "albums")

# Cleanup and prep of deploy space
shutil.rmtree(output_photos_path, ignore_errors=True)
if self.overwrite:
shutil.rmtree(output_photos_path, ignore_errors=True)
os.makedirs(output_photos_path, exist_ok=True)
shutil.rmtree(output_data_path, ignore_errors=True)
os.makedirs(output_data_path, exist_ok=True)
Expand Down

1 comment on commit dd7986f

@miek770
Copy link

@miek770 miek770 commented on dd7986f Jul 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great this seems to address #18, I'm currently rescanning to check if #19's fix works on my end. Thanks.

Please sign in to comment.