Преглед изворни кода

Added condition to exclude files starting with a dot.
Usually those files contains medatada (like .directoty in KDE) and can confuse the generation of thumbnails and galleries.

mikitex70 пре 10 година
родитељ
комит
7e9bbb2c10
2 измењених фајлова са 22 додато и 20 уклоњено
  1. 3 3
      gallery/gallery.py
  2. 19 17
      thumbnailer/thumbnailer.py

+ 3 - 3
gallery/gallery.py

@@ -16,7 +16,7 @@ def add_gallery_post(generator):
 
             if(os.path.isdir(articlegallerypath)):
                 for i in os.listdir(articlegallerypath):
-                    if os.path.isfile(os.path.join(os.path.join(gallerycontentpath, album), i)):
+                    if not a.startswith('.') and os.path.isfile(os.path.join(os.path.join(gallerycontentpath, album), i)):
                         galleryimages.append(i)
 
             article.album = album
@@ -33,10 +33,10 @@ def generate_gallery_page(generator):
             gallery = dict()
 
             for a in os.listdir(gallerycontentpath):
-                if os.path.isdir(os.path.join(gallerycontentpath, a)):
+                if not a.startswith('.') and os.path.isdir(os.path.join(gallerycontentpath, a)):
 
                     for i in os.listdir(os.path.join(gallerycontentpath, a)):
-                        if os.path.isfile(os.path.join(os.path.join(gallerycontentpath, a), i)):
+                        if not a.startswith('.') and os.path.isfile(os.path.join(os.path.join(gallerycontentpath, a), i)):
                             gallery.setdefault(a, []).append(i)
                     gallery[a].sort()
 

+ 19 - 17
thumbnailer/thumbnailer.py

@@ -131,13 +131,14 @@ def resize_thumbnails(pelican):
     logger.debug("Thumbnailer Started")
     for dirpath, _, filenames in os.walk(in_path):
         for filename in filenames:
-            for name, resizer in resizers.items():
-                in_filename = path.join(dirpath, filename)
-                logger.debug("Processing thumbnail {0}=>{1}".format(filename, name))
-                if pelican.settings.get('THUMBNAIL_KEEP_NAME', False):
-                    resizer.resize_file_to(in_filename, path.join(out_path, name), True)
-                else:
-                    resizer.resize_file_to(in_filename, out_path)
+	    if not filename.startswith('.'):
+		for name, resizer in resizers.items():
+		    in_filename = path.join(dirpath, filename)
+		    logger.debug("Processing thumbnail {0}=>{1}".format(filename, name))
+		    if pelican.settings.get('THUMBNAIL_KEEP_NAME', False):
+			resizer.resize_file_to(in_filename, path.join(out_path, name), True)
+		    else:
+			resizer.resize_file_to(in_filename, out_path)
 
 
 def _image_path(pelican):
@@ -163,16 +164,17 @@ def expand_gallery(generator, metadata):
     resizer = _resizer(thumbnail_name, '?x?')
     for dirpath, _, filenames in os.walk(in_path):
         for filename in filenames:
-            url = path.join(dirpath, filename).replace(base_path, "")[1:]
-            url = path.join('/static', generator.settings.get('IMAGE_PATH', DEFAULT_IMAGE_DIR), url).replace('\\', '/')
-            logger.debug("GALLERY: {0}".format(url))
-            thumbnail = resizer.get_thumbnail_name(filename)
-            thumbnail = path.join('/', generator.settings.get('THUMBNAIL_DIR', DEFAULT_THUMBNAIL_DIR), thumbnail).replace('\\', '/')
-            lines.append(template.format(
-                filename=filename,
-                url=url,
-                thumbnail=thumbnail,
-            ))
+	    if not filename.startswith('.'):
+		url = path.join(dirpath, filename).replace(base_path, "")[1:]
+		url = path.join('/static', generator.settings.get('IMAGE_PATH', DEFAULT_IMAGE_DIR), url).replace('\\', '/')
+		logger.debug("GALLERY: {0}".format(url))
+		thumbnail = resizer.get_thumbnail_name(filename)
+		thumbnail = path.join('/', generator.settings.get('THUMBNAIL_DIR', DEFAULT_THUMBNAIL_DIR), thumbnail).replace('\\', '/')
+		lines.append(template.format(
+		    filename=filename,
+		    url=url,
+		    thumbnail=thumbnail,
+		))
     metadata['gallery_content'] = "\n".join(lines)