Removed obsoleted tag of Keywords. Updated code so that pyexiv2-0.1.3 users can now use it too.

svn: r16907
This commit is contained in:
Rob G. Healey 2011-03-24 15:43:41 +00:00
parent 629f521eba
commit f963186e78

View File

@ -25,6 +25,9 @@
# ***************************************************************************** # *****************************************************************************
# Python Modules # Python Modules
# ***************************************************************************** # *****************************************************************************
from decimal import *
getcontext().prec = 4
import os, sys import os, sys
from datetime import datetime, date from datetime import datetime, date
import time import time
@ -44,6 +47,7 @@ from gen.ggettext import gettext as _
_DOWNLOAD_LINK = "http://tilloy.net/dev/pyexiv2/" _DOWNLOAD_LINK = "http://tilloy.net/dev/pyexiv2/"
pyexiv2_required = True pyexiv2_required = True
Min_VERSION_str = "pyexiv2-%d.%d.%d" % (0, 1, 3) Min_VERSION_str = "pyexiv2-%d.%d.%d" % (0, 1, 3)
LesserVersion = False
Min_VERSION = (0, 1, 3) Min_VERSION = (0, 1, 3)
PrefVersion_str = "pyexiv2-%d.%d.%d" % (0, 3, 0) PrefVersion_str = "pyexiv2-%d.%d.%d" % (0, 3, 0)
@ -59,22 +63,18 @@ except ImportError:
"and install, %s .") % ( _DOWNLOAD_LINK, Min_VERSION_str, PrefVersion_str)).encode(sys.getfilesystemencoding()) ) "and install, %s .") % ( _DOWNLOAD_LINK, Min_VERSION_str, PrefVersion_str)).encode(sys.getfilesystemencoding()) )
except AttributeError: except AttributeError:
pyexiv2_required = False LesserVersion = True
if not pyexiv2_required: if not pyexiv2_required:
raise Exception((_("The minimum required version for pyexiv2 must be %s \n" raise Exception((_("The minimum required version for pyexiv2 must be %s \n"
"or greater. You may download it from here: %s\n\n I recommend getting, " "or greater. You may download it from here: %s\n\n I recommend getting, "
"%s .") % ( Min_VERSION_str, _DOWNLOAD_LINK, PrefVersion_str).encode(sys.getfilesystemencoding())) ) "%s .") % ( Min_VERSION_str, _DOWNLOAD_LINK, PrefVersion_str).encode(sys.getfilesystemencoding())) )
# import the required classes for use in this gramplet
from pyexiv2 import ImageMetadata, Rational
from gen.plug import Gramplet from gen.plug import Gramplet
from DateHandler import displayer as _dd from DateHandler import displayer as _dd
import gen.lib import gen.lib
import Utils import Utils
import gen.mime
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Constants # Constants
@ -92,9 +92,6 @@ ImageLongitude = "Exif.GPSInfo.GPSLongitude"
ImageLongitudeRef = "Exif.GPSInfo.GPSLongitudeRef" ImageLongitudeRef = "Exif.GPSInfo.GPSLongitudeRef"
ImageDescription = "Exif.Image.ImageDescription" ImageDescription = "Exif.Image.ImageDescription"
# set up keys for Image IPTC keys
IptcKeywords = "Iptc.Application2.Keywords"
_DATAMAP = [ImageArtist, ImageCopyright, ImageDateTime, _DATAMAP = [ImageArtist, ImageCopyright, ImageDateTime,
ImageLatitude, ImageLatitudeRef, ImageLongitude, ImageLongitudeRef, ImageLatitude, ImageLatitudeRef, ImageLongitude, ImageLongitudeRef,
ImageDescription] ImageDescription]
@ -133,10 +130,7 @@ class MetadataViewer(Gramplet):
# Latitude and Longitude for this image # Latitude and Longitude for this image
("Latitude", _("Latitude"), None, True, [], False, 0, None), ("Latitude", _("Latitude"), None, True, [], False, 0, None),
("Longitude", _("Longitude"), None, True, [], False, 0, None), ("Longitude", _("Longitude"), None, True, [], False, 0, None) ]:
# keywords describing your image
("Keywords", _("Keywords"), None, True, [], False, 0, None) ]:
pos, text, choices, readonly, callback, dirty, default, source = items pos, text, choices, readonly, callback, dirty, default, source = items
row = self.make_row(pos, text, choices, readonly, callback, dirty, default, source) row = self.make_row(pos, text, choices, readonly, callback, dirty, default, source)
@ -184,7 +178,6 @@ class MetadataViewer(Gramplet):
# get mime type and make sure it is an image? # get mime type and make sure it is an image?
mime_type = active_media.get_mime_type() mime_type = active_media.get_mime_type()
mtype = gen.mime.get_description(mime_type)
if mime_type and mime_type.startswith("image"): if mime_type and mime_type.startswith("image"):
value, filetype = mime_type.split("/") value, filetype = mime_type.split("/")
@ -207,16 +200,24 @@ class MetadataViewer(Gramplet):
return return
# define plugin media # define plugin media
self.plugin_image = ImageMetadata(image_path) self.plugin_image = pyexiv2.ImageMetadata(image_path)
# read media metadata if LesserVersion:
try: try:
self.plugin_image.read() self.plugin_image.readMetadata()
except IOError: except IOError:
return return
else:
# read media metadata
try:
self.plugin_image.read()
except IOError:
return
# set up image metadata keys for use in this gramplet # set up image metadata keys for use in this gramplet
dataKeyTags = [KeyTag for KeyTag in self.plugin_image.exif_keys if KeyTag in _DATAMAP ] dataKeyTags = [KeyTag for KeyTag in self.plugin_image.exif_keys if KeyTag in _DATAMAP]
for KeyTag in dataKeyTags: for KeyTag in dataKeyTags:
@ -286,18 +287,6 @@ class MetadataViewer(Gramplet):
self._get_value(ImageDescription) self._get_value(ImageDescription)
) )
# image Keywords
words = ""
keyWords = self._get_value(IptcKeywords)
if keyWords:
index = 1
for word in keyWords:
words += word
if index is not len(keyWords):
words += ","
index += 1
self.exif_widgets["Keywords"].set_text(words)
def make_row(self, pos, text, choices=None, readonly=False, callback_list=[], def make_row(self, pos, text, choices=None, readonly=False, callback_list=[],
mark_dirty=False, default=0, source=None): mark_dirty=False, default=0, source=None):
@ -379,7 +368,7 @@ class MetadataViewer(Gramplet):
""" """
for key in [ "Artist", "Copyright", "NewDate", "NewTime", for key in [ "Artist", "Copyright", "NewDate", "NewTime",
"Latitude", "Longitude", "Keywords", "Description" ]: "Latitude", "Longitude", "Description" ]:
self.exif_widgets[key].set_text( "" ) self.exif_widgets[key].set_text( "" )
def process_date(self, tmpDate): def process_date(self, tmpDate):
@ -496,7 +485,7 @@ def convert_value(value):
will take a value from the coordinates and return its value will take a value from the coordinates and return its value
""" """
if isinstance(value, Rational): if isinstance(value, pyexiv2.Rational):
value = value.numerator value = value.numerator
else: else:
value = (value.numerator / value.denominator) value = (value.numerator / value.denominator)
@ -518,8 +507,7 @@ def rational_to_dms(coords, ValueType):
sec, rest = sec.split("/") sec, rest = sec.split("/")
sec, rest = int(sec), int(rest) sec, rest = int(sec), int(rest)
if rest > 1: sec = str( ( Decimal(sec) / Decimal(rest) ) )
sec = str( (sec/ rest) )
elif (ValueType == 0 and isinstance(coords, list) ): elif (ValueType == 0 and isinstance(coords, list) ):