Merge pull request #242 from xouillet/optim_properties

Optimize properties
This commit is contained in:
Simon Conseil
2017-03-03 22:20:16 +01:00
committed by GitHub
3 changed files with 12 additions and 4 deletions

View File

@@ -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

View File

@@ -102,15 +102,17 @@ 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 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
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
@@ -476,7 +478,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.
@@ -489,6 +491,10 @@ class Album(UnicodeMixin):
if zip_gallery and len(self) > 0:
zip_gallery = zip_gallery.format(album=self)
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')

View File

@@ -188,6 +188,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 = ''