diff options
author | Olivier Tilloy <olivier@tilloy.net> | 2009-04-22 09:55:42 +0200 |
---|---|---|
committer | Olivier Tilloy <olivier@tilloy.net> | 2009-04-22 09:55:42 +0200 |
commit | fc159fa96a9a0d77f21891659e0ea8bc5b3b9f66 (patch) | |
tree | b0c368c9f07fbba01b75180637963cbe6437d87a /src | |
parent | 80c93ece679e312215acb222e3875bcd72044fa1 (diff) | |
download | pyexiv2-fc159fa96a9a0d77f21891659e0ea8bc5b3b9f66.tar.gz |
Delete an XMP tag.
Diffstat (limited to 'src')
-rw-r--r-- | src/exiv2wrapper.cpp | 17 | ||||
-rw-r--r-- | src/exiv2wrapper.hpp | 4 | ||||
-rw-r--r-- | src/exiv2wrapper_python.cpp | 1 | ||||
-rw-r--r-- | src/pyexiv2.py | 10 |
4 files changed, 30 insertions, 2 deletions
diff --git a/src/exiv2wrapper.cpp b/src/exiv2wrapper.cpp index b91a2ac..9b0a5da 100644 --- a/src/exiv2wrapper.cpp +++ b/src/exiv2wrapper.cpp @@ -375,6 +375,23 @@ void Image::setXmpTagValue(std::string key, std::string value) _xmpData[key] = value; } +void Image::deleteXmpTag(std::string key) +{ + if(!_dataRead) + { + throw Exiv2::Error(METADATA_NOT_READ); + } + + Exiv2::XmpKey xmpKey = Exiv2::XmpKey(key); + Exiv2::XmpMetadata::iterator i = _xmpData.findKey(xmpKey); + if(i != _xmpData.end()) + { + _xmpData.erase(i); + } + else + throw Exiv2::Error(KEY_NOT_FOUND, key); +} + /* boost::python::tuple Image::getThumbnailData() { diff --git a/src/exiv2wrapper.hpp b/src/exiv2wrapper.hpp index 02c1d1a..56b636e 100644 --- a/src/exiv2wrapper.hpp +++ b/src/exiv2wrapper.hpp @@ -115,6 +115,10 @@ public: void setXmpTagValue(std::string key, std::string value); + // Delete the required XMP tag. + // Throw an exception if the tag was not set. + void deleteXmpTag(std::string key); + // Read and write access to the thumbnail embedded in the image. // Return a tuple containing the format of the thumbnail ("TIFF" or diff --git a/src/exiv2wrapper_python.cpp b/src/exiv2wrapper_python.cpp index c7bda03..c4eb9d8 100644 --- a/src/exiv2wrapper_python.cpp +++ b/src/exiv2wrapper_python.cpp @@ -63,6 +63,7 @@ BOOST_PYTHON_MODULE(libexiv2python) .def("xmpKeys", &Image::xmpKeys) .def("getXmpTag", &Image::getXmpTag) .def("setXmpTagValue", &Image::setXmpTagValue) + .def("deleteXmpTag", &Image::deleteXmpTag) // .def("getThumbnailData", &Image::getThumbnailData) // .def("setThumbnailData", &Image::setThumbnailData) diff --git a/src/pyexiv2.py b/src/pyexiv2.py index 677ef7e..309c112 100644 --- a/src/pyexiv2.py +++ b/src/pyexiv2.py @@ -1210,8 +1210,14 @@ class ImageMetadata(object): pass def _delete_xmp_tag(self, key): - # TODO - raise NotImplementedError() + if key not in self.xmp_keys: + raise KeyError('Cannot delete an inexistent tag') + self._image.deleteXmpTag(key) + try: + del self._tags['xmp'][key] + except KeyError: + # The tag was not cached. + pass def __delitem__(self, key): """ |