def writePhotoMD(self, imageId, filePath=None):
        """
        Write the metadata from the library for imageId to filePath.
        If filePath is None, write it to the photo in the library.
        If use_faces is True, iPhoto face names will be written to
        keywords.
        """
        try:
            image = self.images[imageId]
        except KeyError:
            raise iPhotoLibraryError, "Can't find image #%s" % imageId

        if not filePath:
            if self.originals:
                if "OriginalPath" in image:
                    mFilePath = image["OriginalPath"]
                else:
                    mFilePath = image["ImagePath"]
            else:
                if not "ImagePath" in image:
                    mFilePath = image["OriginalPath"]
                else:
                    mFilePath = image["ImagePath"]


        caption = image.get("Caption", None)
        rating = image.get("Rating", None)
        comment = image.get("Comment", None)
        keywords = set([self.keywords[k] for k in image.get("Keywords", [])])
        if self.use_faces:
            keywords.update([self.faces[f['face key']]
                             for f in image.get("Faces", [])
                             if self.faces.has_key(f['face key'])]
            )

        if caption or comment or rating or keywords:
            try:
                md = pyexiv2.ImageMetadata(filePath)
                md.read()
                if caption:
                    md["Iptc.Application2.Headline"] = [caption]
                if rating:
                    md["Xmp.xmp.Rating"] = rating
                if comment:
                    md["Iptc.Application2.Caption"] = [comment]
                if keywords:
                    md["Iptc.Application2.Keywords"] = list(keywords)
                if not self.test:
                    md.write(preserve_timestamps=True)
                return True
            except __HOLE__, why:
                self.status("\nProblem setting metadata (%s) on %s\n" % (
                    unicode(why.__str__(), errors='replace'), filePath
                ))
        return False
dataset/ETHPy150Open BMorearty/exportiphoto/exportiphoto.py/iPhotoLibrary.writePhotoMD