From 4c3a35c66fab228a54d7a97219c40b375d8f95e2 Mon Sep 17 00:00:00 2001 From: Simon Conseil Date: Sun, 7 Sep 2014 23:58:39 +0200 Subject: [PATCH] Change where the original copy is done and add a test for this. --- sigal/gallery.py | 19 +++++++------------ tests/test_gallery.py | 11 +++++++---- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/sigal/gallery.py b/sigal/gallery.py index a8b15d4..b78a1af 100644 --- a/sigal/gallery.py +++ b/sigal/gallery.py @@ -92,10 +92,15 @@ class Media(UnicodeMixin): @property def big(self): """Path to the original image, if ``keep_orig`` is set (relative to the - album directory). + album directory). Copy the file if needed. """ if self.settings['keep_orig']: - return os.path.join(self.settings['orig_dir'], self.src_filename) + s = self.settings + 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']) + return url_from_path(join(s['orig_dir'], self.src_filename)) else: return None @@ -185,7 +190,6 @@ class Album(UnicodeMixin): self.name = path.split(os.path.sep)[-1] self.gallery = gallery self.settings = settings - self.orig_path = None self._thumbnail = None if path == '.': @@ -278,10 +282,6 @@ class Album(UnicodeMixin): check_or_create_dir(join(self.dst_path, self.settings['thumb_dir'])) - if self.medias and self.settings['keep_orig']: - self.orig_path = join(self.dst_path, self.settings['orig_dir']) - check_or_create_dir(self.orig_path) - @property def images(self): """List of images (:class:`~sigal.gallery.Image`).""" @@ -560,16 +560,11 @@ class Gallery(object): def process_dir(self, album, force=False): """Process a list of images in a directory.""" - for f in album: if isfile(f.dst_path) and not force: self.logger.info("%s exists - skipping", f.filename) self.stats[f.type + '_skipped'] += 1 else: - if self.settings['keep_orig']: - copy(f.src_path, join(album.orig_path, f.src_filename), - symlink=self.settings['orig_link']) - self.stats[f.type] += 1 yield f.type, f.src_path, album.dst_path, self.settings diff --git a/tests/test_gallery.py b/tests/test_gallery.py index 71d3df7..3fe3e11 100644 --- a/tests/test_gallery.py +++ b/tests/test_gallery.py @@ -78,18 +78,21 @@ def test_media(settings): assert str(m) == file_path -def test_media_orig(settings): +def test_media_orig(settings, tmpdir): settings['keep_orig'] = False m = Media('11.jpg', 'dir1/test1', settings) assert m.big is None settings['keep_orig'] = True + settings['destination'] = str(tmpdir) + m = Image('11.jpg', 'dir1/test1', settings) assert m.big == 'original/11.jpg' - m = Video('file.ogv', 'video', settings) - assert m.filename == 'file.webm' - assert m.big == 'original/file.ogv' + m = Video('stallman software-freedom-day-low.ogv', 'video', settings) + assert m.filename == 'stallman software-freedom-day-low.webm' + assert m.big == 'original/stallman software-freedom-day-low.ogv' + assert os.path.isfile(join(settings['destination'], m.path, m.big)) def test_image(settings, tmpdir):