aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOlivier Tilloy <olivier@tilloy.net>2009-03-12 20:00:30 +0100
committerOlivier Tilloy <olivier@tilloy.net>2009-03-12 20:00:30 +0100
commit1fee371f1496cd2f13b410e00469b307dd56d703 (patch)
tree9175a751f78702ac7b37f11d691f4c1b784a5e40 /src
parent41eea2f150be218f5a4edd2fa1175fa333fdf385 (diff)
downloadpyexiv2-1fee371f1496cd2f13b410e00469b307dd56d703.tar.gz
First version of an ImageMetadata class, meant to replace the Image class.
Diffstat (limited to 'src')
-rw-r--r--src/exiv2wrapper_python.cpp6
-rw-r--r--src/pyexiv2.py60
2 files changed, 63 insertions, 3 deletions
diff --git a/src/exiv2wrapper_python.cpp b/src/exiv2wrapper_python.cpp
index 4c171bd..7d6867b 100644
--- a/src/exiv2wrapper_python.cpp
+++ b/src/exiv2wrapper_python.cpp
@@ -54,18 +54,18 @@ BOOST_PYTHON_MODULE(libexiv2python)
// .def("writeMetadata", &Image::writeMetadata)
.def("exifKeys", &Image::exifKeys)
- .def("_Image__getExifTag", &Image::getExifTag)
+ .def("getExifTag", &Image::getExifTag)
// .def("_Image__getExifTagToString", &Image::getExifTagToString)
// .def("_Image__setExifTag", &Image::setExifTag)
// .def("_Image__deleteExifTag", &Image::deleteExifTag)
.def("iptcKeys", &Image::iptcKeys)
- .def("_Image__getIptcTag", &Image::getIptcTag)
+ .def("getIptcTag", &Image::getIptcTag)
// .def("_Image__setIptcTag", &Image::setIptcTag)
// .def("_Image__deleteIptcTag", &Image::deleteIptcTag)
.def("xmpKeys", &Image::xmpKeys)
- .def("_Image__getXmpTag", &Image::getXmpTag)
+ .def("getXmpTag", &Image::getXmpTag)
// .def("tagDetails", &Image::tagDetails)
diff --git a/src/pyexiv2.py b/src/pyexiv2.py
index b1e7dfc..46128ea 100644
--- a/src/pyexiv2.py
+++ b/src/pyexiv2.py
@@ -941,6 +941,66 @@ class XmpTag(MetadataTag):
return r
+class ImageMetadata(object):
+
+ """
+ DOCME
+ """
+
+ def __init__(self, filename):
+ self.filename = filename
+ if type(filename) is unicode:
+ self.filename = filename.encode('utf-8')
+ self._image = None
+ self._keys = {'exif': None, 'iptc': None, 'xmp': None}
+ self._tags = {'exif': {}, 'iptc': {}, 'xmp': {}}
+
+ def _instantiate_image(self, filename):
+ # This method is meant to be overridden in unit tests to easily replace
+ # the internal image reference by a mock.
+ return libexiv2python.Image(filename)
+
+ def read(self):
+ """
+ DOCME
+ """
+ if self._image is None:
+ self._image = self._instantiate_image(self.filename)
+ self._image.readMetadata()
+
+ def write(self):
+ """
+ DOCME
+ """
+ self._image.writeMetadata()
+
+ @property
+ def exif_keys(self):
+ if self._keys['exif'] is None:
+ self._keys['exif'] = self._image.exifKeys()
+ return self._keys['exif']
+
+ @property
+ def iptc_keys(self):
+ if self._keys['iptc'] is None:
+ self._keys['iptc'] = self._image.iptcKeys()
+ return self._keys['iptc']
+
+ @property
+ def xmp_keys(self):
+ if self._keys['xmp'] is None:
+ self._keys['xmp'] = self._image.xmpKeys()
+ return self._keys['xmp']
+
+ def _get_exif_tag(self, key):
+ try:
+ return self._tags['exif'][key]
+ except KeyError:
+ tag = ExifTag(*self._image.getExifTag(key))
+ self._tags['exif'][key] = tag
+ return tag
+
+
class Image(libexiv2python.Image):
"""