changeset 111:2159a14c54ea

arnica_slides.image_rotate: rotate only image, purge cache of thumbnail and webnail
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Fri, 27 Jun 2008 07:52:37 +0200
parents e2152984f263
children 8438a033d483
files data/plugin/action/arnica_slides.py
diffstat 1 files changed, 11 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/data/plugin/action/arnica_slides.py	Fri Jun 27 07:33:54 2008 +0200
+++ b/data/plugin/action/arnica_slides.py	Fri Jun 27 07:52:37 2008 +0200
@@ -70,24 +70,19 @@
         # send data
         request.send_file(open(fpath, 'rb'))
 
-def image_rotate(file_name, webf, thumbf, angle, img_type):
+def image_rotate(file_name, angle, img_type):
     """ rotates the image and dependent images
 
     @param file: the name of the attachment
-    @param webf: the name of the webnail
-    @param thumbf: the name of the thumbnail
     @param angle: the angle to rotate to
     @param img_type: type of image PNG or JPEG
     """
-    # image needs to be rotated only, webnail and thumbnail removed 
-    # both will be recreated from the arnica parser call
+    # image needs to be rotated only, webnail and thumbnail 
+    # will be recreated from arnica parser
     image_object = Image.open(file_name)
     os.remove(file_name)
     image_object.rotate(angle).save(file_name, img_type)
 
-    os.remove(webf)
-    os.remove(thumbf)
-
 def html_js(request, counter):
     """ javscript for the slides
     @param request: request object
@@ -438,32 +433,31 @@
                 thumbfile = "tmp.thumbnail_%(file)s.jpg"  % {"file": filename}
                 webnail = "tmp.webnail_%(file)s.jpg"  % {"file": filename}
 
-            thumbf = os.path.join(arena_dir, thumbfile)
-            webf = os.path.join(arena_dir, webnail)
             cache_web = caching.CacheEntry(request, page, webnail, scope='item', use_pickle=True)
             cache_thumb = caching.CacheEntry(request, page, thumbfile, scope='item', use_pickle=True)
+            infile = os.path.join(attachment_path, target)
 
-            infile = os.path.join(attachment_path, target)
+            if command in ('delete', 'rotate_left', 'rotate_right'):
+                # removes cache files
+                cache_web.remove()
+                cache_thumb.remove()
 
             # removes attachment (moves to bak)
             if command == 'delete':
                 if os.path.exists(infile + '.bak'):
                     os.unlink("%(file)s.bak" % {"file": infile})
                 filesys.rename(infile, "%(file)s.bak" % {"file": infile})
-                # removes cache files
-                cache_web.remove()
-                cache_thumb.remove()
-
                 msg = _('%(target)s deleted, backup in place' % {
                       'target': target})
+
             # rotate left
             elif command == 'rotate_left':
-                image_rotate(infile, webf, thumbf, 90, img_type)
+                image_rotate(infile, 90, img_type)
                 msg = _('%(target)s rotated to left 90 degrees' % {'target': target})
 
             # rotate right
             elif command == 'rotate_right':
-                image_rotate(infile, webf, thumbf, 270, img_type)
+                image_rotate(infile, 270, img_type)
                 msg = _('%(target)s rotated to right 90 degrees' % {'target': target})
 
             else: