Ver código fonte

refactor out get_out_path into separate function for testing

Dan Fellin 10 anos atrás
pai
commit
805924be79
1 arquivos alterados com 17 adições e 12 exclusões
  1. 17 12
      thumbnailer/thumbnailer.py

+ 17 - 12
thumbnailer/thumbnailer.py

@@ -131,8 +131,6 @@ def resize_thumbnails(pelican):
         return
 
     in_path = _image_path(pelican)
-    out_path = path.join(pelican.settings['OUTPUT_PATH'],
-                         pelican.settings.get('THUMBNAIL_DIR', DEFAULT_THUMBNAIL_DIR))
 
     sizes = pelican.settings.get('THUMBNAIL_SIZES', DEFAULT_THUMBNAIL_SIZES)
     resizers = dict((k, _resizer(k, v, in_path)) for k,v in sizes.items())
@@ -142,16 +140,23 @@ def resize_thumbnails(pelican):
             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):
-                        if pelican.settings.get('THUMBNAIL_KEEP_TREE', False):
-                            resizer.resize_file_to(
-                                in_filename, 
-                                path.join(out_path, name, path.dirname(path.relpath(in_filename, in_path))), True)
-                        else:
-                            resizer.resize_file_to(in_filename, path.join(out_path, name), True)
-                    else:
-                        resizer.resize_file_to(in_filename, out_path)
+                    out_path = get_out_path(pelican, in_path, in_filename, name)
+                    resizer.resize_file_to(
+                        in_filename,
+                        out_path, pelican.settings.get('THUMBNAIL_KEEP_NAME'))
+
+
+def get_out_path(pelican, in_path, in_filename, name):
+    out_path = path.join(pelican.settings['OUTPUT_PATH'],
+                         pelican.settings.get('THUMBNAIL_DIR', DEFAULT_THUMBNAIL_DIR))
+    logger.debug("Processing thumbnail {0}=>{1}".format(in_filename, name))
+    if pelican.settings.get('THUMBNAIL_KEEP_NAME', False):
+        if pelican.settings.get('THUMBNAIL_KEEP_TREE', False):
+            return path.join(out_path, name, path.dirname(path.relpath(in_filename, in_path)))
+        else:
+            return path.join(out_path, name)
+    else:
+        return out_path
 
 
 def _image_path(pelican):