make loading exif metadata optional
authorTero Marttila <terom@fixme.fi>
Sun, 14 Jun 2009 16:34:40 +0300
changeset 111 ecceaf23c969
parent 110 a5b30b423f79
child 112 e990b7a54d40
make loading exif metadata optional
degal/config.py
degal/image.py
degal/main.py
--- a/degal/config.py	Sun Jun 14 16:27:03 2009 +0300
+++ b/degal/config.py	Sun Jun 14 16:34:40 2009 +0300
@@ -38,6 +38,10 @@
     # number of images displayed per folder page
     images_per_page     = 50
     
+    # load Exif data for images
+    # this may be slow
+    exif_enabled        = False
+
     # exif tags used in output
     # Copyright (C) 2008, Santtu Pajukanta <santtu@pajukanta.fi>
     # XXX: import from dexif?
--- a/degal/image.py	Sun Jun 14 16:27:03 2009 +0300
+++ b/degal/image.py	Sun Jun 14 16:34:40 2009 +0300
@@ -74,20 +74,28 @@
 
         # load stuff
         stat = self.stat()
-        exif = self.exif
 
         # XXX: avoid having to open the image?
         size = self.pil_image.size
         
         # build
-        return dict({
+        metadata = dict({
             "File name":        self.name,
             "Resolution":       "%dx%d" % size,
             "File size":        format.filesize(stat.st_size),
             "Last modified":    format.filetime(stat.st_mtime),
-        }, **dict(
-            (name, exif[tag]) for tag, name in self.config.exif_tags if exif and tag in exif
-        ))
+        })
+        
+        # optionally load Exif metadata
+        if self.config.exif_enabled :
+            exif = self.exif
+
+            # Get the wanted tags
+            metadata.update(dict(
+                (name, exif[tag]) for tag, name in self.config.exif_tags if exif and tag in exif
+            ))
+
+        return metadata
     
     def stale (self) :
         """
--- a/degal/main.py	Sun Jun 14 16:27:03 2009 +0300
+++ b/degal/main.py	Sun Jun 14 16:34:40 2009 +0300
@@ -26,6 +26,9 @@
 
     parser.add_option("--force-html",           dest='force_html', action="store_true", default=False,
             help="Force-update all .html files")
+    
+    parser.add_option("--with-exif",            dest='exif_enabled', action="store_true", default=None,
+            help="Include Exif metadata in updated .html files")
 
     parser.add_option('-d', "--debug",          dest='debug', action="store_true", default=False,
             help="Show debug output")
@@ -57,6 +60,9 @@
     if options.force_html :
         config.force_html = True
 
+    if options.exif_enabled is not None :
+        config.exif_enabled = options.exif_enabled
+
     if options.debug :
         config.log_level = config_module.logging.DEBUG