From 746c313a8d5b9cf71bf8ef1e6d0df20be24db7f4 Mon Sep 17 00:00:00 2001 From: Alexandre Chataignon Date: Thu, 8 Dec 2016 05:38:33 +0100 Subject: [PATCH 1/5] Optimisation when using keep_orig --- sigal/gallery.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sigal/gallery.py b/sigal/gallery.py index 261531e..3b30fb1 100644 --- a/sigal/gallery.py +++ b/sigal/gallery.py @@ -101,8 +101,10 @@ class Media(UnicodeMixin): return self.filename orig_path = join(s['destination'], self.path, s['orig_dir']) check_or_create_dir(orig_path) - copy(self.src_path, join(orig_path, self.src_filename), - symlink=s['orig_link']) + big_path = join(orig_path, self.src_filename) + if not os.path.isfile(big_path): + copy(self.src_path, big_path, + symlink=s['orig_link']) return url_from_path(join(s['orig_dir'], self.src_filename)) @property From fc8e9b9b5115f87eeefece6be7d7d0415e824628 Mon Sep 17 00:00:00 2001 From: Alexandre Chataignon Date: Fri, 3 Mar 2017 04:55:02 +0100 Subject: [PATCH 2/5] Set @cached_property to avoid generating zip multiple times --- sigal/gallery.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sigal/gallery.py b/sigal/gallery.py index 3b30fb1..143b1ca 100644 --- a/sigal/gallery.py +++ b/sigal/gallery.py @@ -470,7 +470,7 @@ class Album(UnicodeMixin): """ return any(image.has_location() for image in self.images) - @property + @cached_property def zip(self): """Make a ZIP archive with all media files and return its path. From fde26ec8de85c7e61aacadad497dceb341efd069 Mon Sep 17 00:00:00 2001 From: Alexandre Chataignon Date: Fri, 3 Mar 2017 06:37:11 +0100 Subject: [PATCH 3/5] Added setting to skip archive generation if archive file is already present --- sigal/gallery.py | 4 ++++ sigal/templates/sigal.conf.py | 1 + 2 files changed, 5 insertions(+) diff --git a/sigal/gallery.py b/sigal/gallery.py index 143b1ca..9a6064e 100644 --- a/sigal/gallery.py +++ b/sigal/gallery.py @@ -482,6 +482,10 @@ class Album(UnicodeMixin): if zip_gallery and len(self) > 0: archive_path = join(self.dst_path, zip_gallery) + if self.settings.get('zip_skip_if_exists', False) and isfile(archive_path): + self.logger.debug("Archive %s already created, passing", archive_path) + return zip_gallery + archive = zipfile.ZipFile(archive_path, 'w', allowZip64=True) attr = ('src_path' if self.settings['zip_media_format'] == 'orig' else 'dst_path') diff --git a/sigal/templates/sigal.conf.py b/sigal/templates/sigal.conf.py index 1ec4abb..30b4fb4 100644 --- a/sigal/templates/sigal.conf.py +++ b/sigal/templates/sigal.conf.py @@ -187,6 +187,7 @@ ignore_files = [] # contain all resized or original files (depending on `zip_media_format`). # zip_gallery = False # False or 'archive.zip' # zip_media_format = 'resized' # 'resized' or 'orig' +# zip_skip_if_exists = false # Skip archive generation if archive is already present. Warning: new photos in an album won't be added to archive # Specify a different locale. If set to '', the default locale is used. # locale = '' From d4857ffd3f295214ef782eb38e0789729e6ae1b1 Mon Sep 17 00:00:00 2001 From: Alexandre Chataignon Date: Fri, 3 Mar 2017 15:48:36 +0100 Subject: [PATCH 4/5] Fixed typo, changed os.path.isfile to isfile for consistency --- sigal/gallery.py | 4 ++-- sigal/templates/sigal.conf.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sigal/gallery.py b/sigal/gallery.py index 9a6064e..f44cb1a 100644 --- a/sigal/gallery.py +++ b/sigal/gallery.py @@ -102,7 +102,7 @@ class Media(UnicodeMixin): orig_path = join(s['destination'], self.path, s['orig_dir']) check_or_create_dir(orig_path) big_path = join(orig_path, self.src_filename) - if not os.path.isfile(big_path): + if not isfile(big_path): copy(self.src_path, big_path, symlink=s['orig_link']) return url_from_path(join(s['orig_dir'], self.src_filename)) @@ -111,7 +111,7 @@ class Media(UnicodeMixin): def thumbnail(self): """Path to the thumbnail image (relative to the album directory).""" - if not os.path.isfile(self.thumb_path): + if not isfile(self.thumb_path): # if thumbnail is missing (if settings['make_thumbs'] is False) if self.type == 'image': generator = image.generate_thumbnail diff --git a/sigal/templates/sigal.conf.py b/sigal/templates/sigal.conf.py index 30b4fb4..1093642 100644 --- a/sigal/templates/sigal.conf.py +++ b/sigal/templates/sigal.conf.py @@ -187,7 +187,7 @@ ignore_files = [] # contain all resized or original files (depending on `zip_media_format`). # zip_gallery = False # False or 'archive.zip' # zip_media_format = 'resized' # 'resized' or 'orig' -# zip_skip_if_exists = false # Skip archive generation if archive is already present. Warning: new photos in an album won't be added to archive +# zip_skip_if_exists = False # Skip archive generation if archive is already present. Warning: new photos in an album won't be added to archive # Specify a different locale. If set to '', the default locale is used. # locale = '' From cd31b90343b508fc10d8b720aa5b4b34856bc7c0 Mon Sep 17 00:00:00 2001 From: Alexandre Chataignon Date: Fri, 3 Mar 2017 15:50:19 +0100 Subject: [PATCH 5/5] Update AUTHORS --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 2430eed..b17041d 100644 --- a/AUTHORS +++ b/AUTHORS @@ -2,6 +2,7 @@ Sigal is written and maintained by Simon Conseil and contributors (in alphabetical order): - Abdul Qabiz +- Alexandre Chataignon (@xouillet) - Alexey Bazhin - Andreas Sieferlinger - Antoine Pitrou