diff options
| author | 2013-01-02 08:35:03 -0300 | |
|---|---|---|
| committer | 2013-01-02 08:35:03 -0300 | |
| commit | 9c5708cc92af894e414bc76ee35ec2230de5d288 (patch) | |
| tree | 61bd56b5517a4713626c254981143e008c719469 /nikola/plugins/task_render_galleries.py | |
| parent | 0f2c04e70a0ffdd0892d6970cafbcd952d221db5 (diff) | |
Imported Upstream version 5.1upstream/5.1
Diffstat (limited to 'nikola/plugins/task_render_galleries.py')
| -rw-r--r-- | nikola/plugins/task_render_galleries.py | 81 |
1 files changed, 53 insertions, 28 deletions
diff --git a/nikola/plugins/task_render_galleries.py b/nikola/plugins/task_render_galleries.py index 27e13ea..72d0581 100644 --- a/nikola/plugins/task_render_galleries.py +++ b/nikola/plugins/task_render_galleries.py @@ -1,3 +1,28 @@ +# Copyright (c) 2012 Roberto Alsina y otros. + +# Permission is hereby granted, free of charge, to any +# person obtaining a copy of this software and associated +# documentation files (the "Software"), to deal in the +# Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the +# Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice +# shall be included in all copies or substantial portions of +# the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS +# OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +from __future__ import unicode_literals import codecs import datetime import glob @@ -23,7 +48,7 @@ from nikola import utils class Galleries(Task): """Copy theme assets into output.""" - name = "render_galleries" + name = str("render_galleries") dates = {} def gen_tasks(self): @@ -33,6 +58,7 @@ class Galleries(Task): 'thumbnail_size': self.site.config['THUMBNAIL_SIZE'], 'max_image_size': self.site.config['MAX_IMAGE_SIZE'], 'output_folder': self.site.config['OUTPUT_FOLDER'], + 'cache_folder': self.site.config['CACHE_FOLDER'], 'default_lang': self.site.config['DEFAULT_LANG'], 'blog_description': self.site.config['BLOG_DESCRIPTION'], 'use_filename_as_title': self.site.config['USE_FILENAME_AS_TITLE'], @@ -48,7 +74,7 @@ class Galleries(Task): gallery_list.append(root) if not gallery_list: yield { - 'basename': 'render_galleries', + 'basename': str('render_galleries'), 'actions': [], } return @@ -66,8 +92,8 @@ class Galleries(Task): self.site.path("gallery", gallery_name, None))) if not os.path.isdir(output_gallery): yield { - 'basename': 'render_galleries', - 'name': output_gallery, + 'basename': str('render_galleries'), + 'name': str(output_gallery), 'actions': [(os.makedirs, (output_gallery,))], 'targets': [output_gallery], 'clean': True, @@ -91,8 +117,8 @@ class Galleries(Task): except IOError: excluded_image_name_list = [] - excluded_image_list = map(add_gallery_path, - excluded_image_name_list) + excluded_image_list = list(map(add_gallery_path, + excluded_image_name_list)) image_set = set(image_list) - set(excluded_image_list) image_list = list(image_set) except IOError: @@ -107,17 +133,16 @@ class Galleries(Task): # TODO: write this in human paths = ['/'.join(['..'] * (len(crumbs) - 1 - i)) for i in range(len(crumbs[:-1]))] + ['#'] - crumbs = zip(paths, crumbs) + crumbs = list(zip(paths, crumbs)) image_list = [x for x in image_list if "thumbnail" not in x] # Sort by date - image_list.sort(cmp=lambda a, b: cmp( - self.image_date(a), self.image_date(b))) + image_list.sort(key=lambda a: self.image_date(a)) image_name_list = [os.path.basename(x) for x in image_list] thumbs = [] # Do thumbnails and copy originals - for img, img_name in zip(image_list, image_name_list): + for img, img_name in list(zip(image_list, image_name_list)): # img is "galleries/name/image_name.jpg" # img_name is "image_name.jpg" # fname, ext are "image_name", ".jpg" @@ -130,8 +155,8 @@ class Galleries(Task): orig_dest_path = os.path.join(output_gallery, img_name) thumbs.append(os.path.basename(thumb_path)) yield { - 'basename': 'render_galleries', - 'name': thumb_path, + 'basename': str('render_galleries'), + 'name': thumb_path.encode('utf8'), 'file_dep': [img], 'targets': [thumb_path], 'actions': [ @@ -142,8 +167,8 @@ class Galleries(Task): 'uptodate': [utils.config_changed(kw)], } yield { - 'basename': 'render_galleries', - 'name': orig_dest_path, + 'basename': str('render_galleries'), + 'name': orig_dest_path.encode('utf8'), 'file_dep': [img], 'targets': [orig_dest_path], 'actions': [ @@ -165,8 +190,8 @@ class Galleries(Task): fname + ".thumbnail" + ext) excluded_dest_path = os.path.join(output_gallery, img_name) yield { - 'basename': 'render_galleries', - 'name': excluded_thumb_dest_path, + 'basename': str('render_galleries'), + 'name': excluded_thumb_dest_path.encode('utf8'), 'file_dep': [exclude_path], #'targets': [excluded_thumb_dest_path], 'actions': [ @@ -176,8 +201,8 @@ class Galleries(Task): 'uptodate': [utils.config_changed(kw)], } yield { - 'basename': 'render_galleries', - 'name': excluded_dest_path, + 'basename': str('render_galleries'), + 'name': excluded_dest_path.encode('utf8'), 'file_dep': [exclude_path], #'targets': [excluded_dest_path], 'actions': [ @@ -193,11 +218,11 @@ class Galleries(Task): context["title"] = os.path.basename(gallery_path) context["description"] = kw["blog_description"] if kw['use_filename_as_title']: - img_titles = ['title="%s"' % utils.unslugify(fn[:-4]) + img_titles = ['id="%s" alt="%s" title="%s"' % (fn[:-4], fn[:-4], utils.unslugify(fn[:-4])) for fn in image_name_list] else: img_titles = [''] * len(image_name_list) - context["images"] = zip(image_name_list, thumbs, img_titles) + context["images"] = list(zip(image_name_list, thumbs, img_titles)) context["folders"] = folder_list context["crumbs"] = crumbs context["permalink"] = self.site.link( @@ -206,14 +231,14 @@ class Galleries(Task): # Use galleries/name/index.txt to generate a blurb for # the gallery, if it exists index_path = os.path.join(gallery_path, "index.txt") - cache_dir = os.path.join('cache', 'galleries') + cache_dir = os.path.join(kw["cache_folder"], 'galleries') if not os.path.isdir(cache_dir): os.makedirs(cache_dir) - index_dst_path = os.path.join(cache_dir, unicode(uuid.uuid1())+'.html') + index_dst_path = os.path.join(cache_dir, str(uuid.uuid1())+'.html') if os.path.exists(index_path): compile_html = self.site.get_compiler(index_path) yield { - 'basename': 'render_galleries', + 'basename': str('render_galleries'), 'name': index_dst_path.encode('utf-8'), 'file_dep': [index_path], 'targets': [index_dst_path], @@ -236,8 +261,8 @@ class Galleries(Task): self.site.render_template(template_name, output_name, context) yield { - 'basename': 'render_galleries', - 'name': output_name, + 'basename': str('render_galleries'), + 'name': output_name.encode('utf8'), 'file_dep': file_dep, 'targets': [output_name], 'actions': [(render_gallery, @@ -262,7 +287,7 @@ class Galleries(Task): except Exception: exif = None if exif is not None: - for tag, value in exif.items(): + for tag, value in list(exif.items()): decoded = ExifTags.TAGS.get(tag, tag) if decoded == 'Orientation': @@ -284,13 +309,13 @@ class Galleries(Task): def image_date(self, src): """Try to figure out the date of the image.""" if src not in self.dates: - im = Image.open(src) try: + im = Image.open(src) exif = im._getexif() except Exception: exif = None if exif is not None: - for tag, value in exif.items(): + for tag, value in list(exif.items()): decoded = ExifTags.TAGS.get(tag, tag) if decoded == 'DateTimeOriginal': try: |
