diff options
author | Olivier Tilloy <olivier@tilloy.net> | 2009-04-21 20:14:39 +0200 |
---|---|---|
committer | Olivier Tilloy <olivier@tilloy.net> | 2009-04-21 20:14:39 +0200 |
commit | a23bf770e4621a5dc65fccf723edd01ea7deec7c (patch) | |
tree | 68d406f00fd762adf79281178090d1f0c0f78933 /src | |
parent | 279b974080eafb42af1f8da3920e2c4d04e63a0f (diff) | |
download | pyexiv2-a23bf770e4621a5dc65fccf723edd01ea7deec7c.tar.gz |
Private value setter for XMP tags.
Diffstat (limited to 'src')
-rw-r--r-- | src/exiv2wrapper.cpp | 40 | ||||
-rw-r--r-- | src/exiv2wrapper.hpp | 2 | ||||
-rw-r--r-- | src/exiv2wrapper_python.cpp | 1 | ||||
-rw-r--r-- | src/pyexiv2.py | 14 |
4 files changed, 18 insertions, 39 deletions
diff --git a/src/exiv2wrapper.cpp b/src/exiv2wrapper.cpp index 4c37fd6..b91a2ac 100644 --- a/src/exiv2wrapper.cpp +++ b/src/exiv2wrapper.cpp @@ -365,49 +365,15 @@ boost::python::tuple Image::getXmpTag(std::string key) return boost::python::make_tuple(key, sTagName, sTagLabel, sTagDesc, sTagType, sTagValue); } -/*void Image::setXmpTagValues(std::string key, boost::python::tuple values) +void Image::setXmpTagValue(std::string key, std::string value) { if (!_dataRead) { throw Exiv2::Error(METADATA_NOT_READ); } - Exiv2::XmpKey xmpKey = Exiv2::XmpKey(key); - unsigned int index = 0; - unsigned int max = len(values); - Exiv2::XmpMetadata::iterator dataIterator = _xmpData.findKey(xmpKey); - while (index < max) - { - std::string value = boost::python::extract<std::string>(values[index++]); - if (dataIterator != _xmpData.end()) - { - // Override an existing value - dataIterator->setValue(value); - dataIterator = std::find_if(++dataIterator, _xmpData.end(), - Exiv2::FindMetadatumById::FindMetadatumById(xmpKey.tag(), - xmpKey.record())); - } - else - { - // Append a new value - Exiv2::Iptcdatum iptcDatum(iptcKey); - iptcDatum.setValue(value); - int state = _iptcData.add(iptcDatum); - if (state == 6) - { - throw Exiv2::Error(NON_REPEATABLE); - } - } - } - // Erase the remaining values if any - while (dataIterator != _iptcData.end()) - { - _iptcData.erase(dataIterator); - dataIterator = std::find_if(dataIterator, _iptcData.end(), - Exiv2::FindMetadatumById::FindMetadatumById(iptcKey.tag(), - iptcKey.record())); - } -}*/ + _xmpData[key] = value; +} /* boost::python::tuple Image::getThumbnailData() diff --git a/src/exiv2wrapper.hpp b/src/exiv2wrapper.hpp index 0e66f50..02c1d1a 100644 --- a/src/exiv2wrapper.hpp +++ b/src/exiv2wrapper.hpp @@ -113,7 +113,7 @@ public: // tagvalue (list) boost::python::tuple getXmpTag(std::string key); - void setXmpTagValues(std::string key, boost::python::tuple values); + void setXmpTagValue(std::string key, std::string value); // Read and write access to the thumbnail embedded in the image. diff --git a/src/exiv2wrapper_python.cpp b/src/exiv2wrapper_python.cpp index 2be9843..c7bda03 100644 --- a/src/exiv2wrapper_python.cpp +++ b/src/exiv2wrapper_python.cpp @@ -62,6 +62,7 @@ BOOST_PYTHON_MODULE(libexiv2python) .def("xmpKeys", &Image::xmpKeys) .def("getXmpTag", &Image::getXmpTag) + .def("setXmpTagValue", &Image::setXmpTagValue) // .def("getThumbnailData", &Image::getThumbnailData) // .def("setThumbnailData", &Image::setThumbnailData) diff --git a/src/pyexiv2.py b/src/pyexiv2.py index 65bcce7..e550a01 100644 --- a/src/pyexiv2.py +++ b/src/pyexiv2.py @@ -1005,6 +1005,14 @@ class XmpTag(MetadataTag): raise NotImplementedError('XMP conversion for type [%s]' % xtype) + def to_string(self): + """ + Return a string representation of the XMP tag suitable to pass to + libexiv2 to set the value of the tag. + DOCME + """ + return XmpTag._convert_to_string(self.value, self.xtype) + def __str__(self): """ Return a string representation of the XMP tag. @@ -1163,7 +1171,11 @@ class ImageMetadata(object): # the internal cache (which would leave the object in an inconsistent # state). # TODO - raise NotImplementedError() + if key not in self.xmp_keys: + raise KeyError('Cannot set the value of an inexistent tag') + if type(value) is not str: + raise TypeError('Expecting a string') + self._image.setXmpTagValue(key, value) def __setitem__(self, key, tag): """ |