changeset 196:ce2e7a350435

text_x_arnica: refactored get_exif_info to a method of the parser and added caching capability
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sun, 20 Jul 2008 17:02:13 +0200
parents 17c81c85637f
children 459dbc1b8bd5
files data/plugin/parser/text_x_arnica.py
diffstat 1 files changed, 36 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/data/plugin/parser/text_x_arnica.py	Sun Jul 20 16:18:13 2008 +0200
+++ b/data/plugin/parser/text_x_arnica.py	Sun Jul 20 17:02:13 2008 +0200
@@ -170,31 +170,7 @@
     return locals()
 
 
-def get_exif_info(file_name):
-    """ gets exif info from image file
-
-    @param: image file name
-    """
-    date = "--"
-    rawExif = None
-    if not (Image and ExifTags):
-        # in that case no hint about a missing module
-        return date
 
-    if wikiutil.isPicture(file_name):
-        try:
-            im = Image.open(file_name)
-            rawExif = im._getexif().items()
-        except (IOError, AttributeError):
-            pass
-
-        if rawExif:
-            for key, value in sorted(rawExif):
-                if ExifTags.TAGS.get(key) == 'DateTimeOriginal':
-                    date = str(value)
-                    date = date.replace(':', '-', 2)
-                    break
-    return date
 
 def _get_files(request, pagename):
     # get files dependent on isPicture and ignores tmp. files
@@ -239,6 +215,41 @@
         self.imgtype = [] # array of imagetype of high_resolution_image image
         self.description = [] # array of description
         self.webnail_image = [] # array of images for forms
+        
+    def get_exif_info(self, file_name, key):
+        """ gets exif info from image file
+
+        @param: image file name
+        @key: cache key for file_name
+        """
+        date = "--"
+        rawExif = None
+        if not (Image and ExifTags):
+            # in that case no hint about a missing module
+            return date
+
+        if wikiutil.isPicture(file_name):
+            date_key = 'D%s' % key
+
+            cache_date = caching.CacheEntry(self.request, cache.cache_arena, date_key+'.data',
+                                       cache.cache_scope, do_locking=False)
+            if cache_date.exists():
+                return cache_date.content()
+
+            try:
+                im = Image.open(file_name)
+                rawExif = im._getexif().items()
+            except (IOError, AttributeError):
+                pass
+
+            if rawExif:
+                for key, value in sorted(rawExif):
+                    if ExifTags.TAGS.get(key) == 'DateTimeOriginal':
+                        date = str(value)
+                        date = date.replace(':', '-', 2)
+                        cache.put(self.request, date_key, date, filename=file_name, content_type='text/plain')
+                        break
+        return date
 
     def html_tools_restricted(self, this_target):
         """ shows restricted tools
@@ -429,7 +440,7 @@
             if os.path.exists(att_file):
                 self.web_key.append(webnail)
                 self.thumb_key.append(thumbfile)
-                date = get_exif_info(att_file)
+                date = self.get_exif_info(att_file, key)
                 self.exif_date.append(self.formatter.text(date))
 
     def to_wikitext(self, text):