changeset 14:87d11a4031e3

text_x_arnica: thumbnails stored for each page in the cache dir
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Wed, 21 May 2008 13:49:31 +0200
parents cd19dc74d179
children 46267a5a1451
files data/plugin/parser/text_x_arnica.py
diffstat 1 files changed, 42 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/data/plugin/parser/text_x_arnica.py	Sun Mar 09 19:08:28 2008 +0100
+++ b/data/plugin/parser/text_x_arnica.py	Wed May 21 13:49:31 2008 +0200
@@ -74,8 +74,9 @@
 Dependencies = ['time'] # do not cache
 
 import os, re
+from StringIO import StringIO
 from random import randint
-from MoinMoin import wikiutil
+from MoinMoin import caching, wikiutil
 from MoinMoin.action import AttachFile
 from MoinMoin.Page import Page
 from MoinMoin.filter import EXIF
@@ -344,7 +345,18 @@
 
     def mode1_html(self, idx):
         """ html code of mode 1 (default)"""
-        print AttachFile.attachUrl(self.request, self.pagename, self.thumb[idx], target=self.thumb[idx])
+        
+        print AttachFile.attachUrl(self.request, self.pagename, self.thumb[idx], target=self.web[idx])
+        page = Page(self.request, self.pagename)
+        arena_dir = caching.get_arena_dir(self.request, page, 'item')
+        print  arena_dir
+        print self.thumb[idx]
+        webf = os.path.join(arena_dir,  self.web[idx])
+        thumbf = os.path.join(arena_dir, self.thumb[idx])
+        print thumbf
+        
+        #cache_thumb= caching.CacheEntry(self.request, page, self.thumb[idx], scope='item', use_pickle=True) 
+        
         text = '''
     <table width="%(thumbnail_width)s" align="center" valign="center"%(style)s>
     <TR align="center" valign="center">
@@ -356,7 +368,7 @@
                 <input type="hidden" name="alias" value='%(description)s'>
                 <input type="hidden" name="exif_date" value='%(exif_date)s'>
                 <input type="hidden" name="target" value='%(target)s'>
-                <input type="image" value="submit" src="%(thumbnail)s" >
+                <input type="image" value="submit" type="button" src="file://%(thumbnail)s" >
             </td>
         </form>
     </TR>
@@ -371,7 +383,7 @@
      "description": self.description[idx] + '!,!' + '!,!'.join(self.description),
      "exif_date": self.exif_date[idx] + ',' + ','.join(self.exif_date),
      "target": self.webimg[idx] + ',' + ','.join(self.webimg),
-     "thumbnail":"%s%s" % (AttachFile.getAttachUrl(self.pagename, '', self.request), self.thumb[idx]),
+     "thumbnail":"%s" % thumbf,
      "thumbnail_width": self.thumbnail_width,
      "tools_html": self.show_tools_mode1(idx),
      "date_html": self.show_date_mode1(idx),
@@ -525,41 +537,46 @@
         return all_files
     
     def create_thumbnail_and_webnail(self, image, webnail, thumbnail, image_type):
-        """creates thumbnails and webnails for given image type
+        """creates thumbnails and webnails cache files for given image type
         @param image: filename of image
-        @param webnail: filename of webnail file
-        @param thumbnail: filename of thumbnail file
+        @param webnail: name of webnail file
+        @param thumbnail: name of thumbnail file
         @param image_type: filetype of image
         """
         path = AttachFile.getAttachDir(self.request, self.pagename, create=1)
         imagef = os.path.join(path, image)
-        webf = os.path.join(path, webnail)
-        thumbf = os.path.join(path, thumbnail) 
-        
+
+       
+        page = Page(self.request, self.pagename)
+        cache_web = caching.CacheEntry(self.request, page, webnail, scope='item', use_pickle=True)        
+        cache_thumb= caching.CacheEntry(self.request, page, thumbnail, scope='item', use_pickle=True) 
+
+        arena_dir = caching.get_arena_dir(self.request, page, 'item')
+        webf = os.path.join(arena_dir, webnail)
+        thumbf = os.path.join(arena_dir, thumbnail)
+
         if self.renew == '1':
-            if os.path.exists(thumbf):
-                os.unlink(thumbf)
-            if os.path.exists(webf):
-                os.unlink(webf)
+            cache_web.remove()
+            cache_thumb.remove()
+
+        if not cache_web.exists() or not cache_thumb.exists():
+            im_obj = Image.open(imagef)
+            if not cache_web.exists():
+                if self.image_for_webnail == '1':
+                   os.link(imagef, webf)
+                else:
+                    im_obj.thumbnail((int(self.webnail_width), int(self.webnail_width)), Image.ANTIALIAS)
+                    im_obj.save(webf, image_type)
                     
-        if not os.path.exists(webf) or not os.path.exists(thumbf):
-            im_obj = Image.open(imagef)
-            if not os.path.exists(webf):
-                im_obj.thumbnail((int(self.webnail_width), int(self.webnail_width)), Image.ANTIALIAS)
-                if self.image_for_webnail == '1':
-                    os.link(imagef, webf)
-                else:
-                    im_obj.save(webf, image_type)
-            if not os.path.exists(thumbf):
+            if not cache_thumb.exists():
                 im_obj.thumbnail(((int(self.thumbnail_width)), ((int(self.thumbnail_width)))),
                                Image.ANTIALIAS)
                 im_obj.save(thumbf, image_type)
-
                 
     def format(self, formatter):
         """ does the format """
         _ = self._
-
+        page = formatter.page
         if self.help == '1':
             self.print_help()
             return