1
# Lazygal, a lazy static web gallery generator.
2
# Copyright (C) 2013 Alexandre Rossi <alexandre.rossi@gmail.com>
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License along
15
# with this program; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
This is a transition module to provide pyexiv2 compatibility waiting for
21
a properly supported GExiv2 windows port.
29
class Metadata_withPyExiv2(object):
31
def __init__(self, image_path):
32
self.pyexiv2md = pyexiv2.metadata.ImageMetadata(image_path)
35
def __getitem__(self, key):
37
val = self.pyexiv2md[key].value
40
if type(val) is datetime.datetime:
41
val = val.strftime('%Y:%m:%d %H:%M:%S')
44
def __setitem__(self, key, value):
45
if value == '' or value is None:
46
del self.pyexiv2md[key]
49
if key in ('Iptc.Application2.Keywords',
50
'Xmp.MicrosoftPhoto.LastKeywordXMP',
52
'Xmp.digiKam.TagsList', ):
53
if type(value) is not list:
56
if key in self.pyexiv2md.exif_keys:
57
tag = pyexiv2.exif.ExifTag(key)
58
if tag.type in ('Long', 'SLong', 'Short', 'SShort', ):
60
elif tag.type == 'Undefined':
62
self.pyexiv2md[key] = tag
65
self.pyexiv2md[key] = value
67
def __contains__(self, key):
68
return key in self.pyexiv2md
70
def get_tag_interpreted_string(self, key):
71
return self.pyexiv2md[key].human_value
73
def get_tag_multiple(self, key):
74
return self.pyexiv2md[key].value
76
def get_exif_tag_rational(self, key):
77
return self.pyexiv2md[key].value
79
def get_comment(self):
80
return self.pyexiv2md.comment
82
def get_exif_tags(self):
83
return self.pyexiv2md.exif_keys
85
def clear_tag(self, key):
86
del self.pyexiv2md[key]
89
self.pyexiv2md.write()
92
class GExiv2_withPyExiv2(object):
93
Metadata = Metadata_withPyExiv2
95
class LogLevel(object):
99
def log_set_level(dummy):
104
from gi.repository import GExiv2
107
logging.warning('Falling back to try using pyexiv2, which is deprecated.')
109
warnings.warn("deprecated", DeprecationWarning)
110
GExiv2 = GExiv2_withPyExiv2
113
# vim: ts=4 sw=4 expandtab