changeset 194:57609945a3f5

text_x_arnica: removed dependeny of filter.EXIF, exif tags by Image and ExifTags
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sun, 20 Jul 2008 16:09:12 +0200
parents 5c37c14532dc
children 17c81c85637f
files data/plugin/parser/text_x_arnica.py
diffstat 1 files changed, 22 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/data/plugin/parser/text_x_arnica.py	Sat Jul 19 23:06:38 2008 +0200
+++ b/data/plugin/parser/text_x_arnica.py	Sun Jul 20 16:09:12 2008 +0200
@@ -19,7 +19,6 @@
 
 from MoinMoin import caching, config, wikiutil
 from MoinMoin.action import AttachFile, cache
-from MoinMoin.filter import EXIF
 from MoinMoin.packages import packLine
 from MoinMoin.Page import Page
 from MoinMoin.util.dataset import TupleDataset, Column
@@ -29,6 +28,11 @@
     import Image
 except ImportError:
     Image = None
+    
+try:
+    import ExifTags
+except ImportError:
+    ExifTags = None    
 
 parser_name = __name__.split('.')[-1]
 
@@ -166,23 +170,31 @@
     return locals()
 
 
-# ToDo may be move to wikiutil
 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):
-        # if there is no exif data available, tags is an empty dict
-        exif_file = open(file_name, 'rb')
-        tags = EXIF.process_file(exif_file, 'DateTimeOriginal')
-        exif_file.close()
-        if 'EXIF DateTimeOriginal' in tags:
-            date = str(tags['EXIF DateTimeOriginal'])
-            date = date.replace(':', '-', 2)
-    return date
+        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