def changeCaption(self, name, caption, writeToFile = False): """Changes the caption of image 'name' to 'caption'. Optionally, writes the new caption to the image file after changeing. """ assert name in self.entries while len(caption) > 0 and caption[-1] == "\n": caption = caption[:-1] caption = re.sub("\\\n", "<br />", caption) if name not in self.captions or self.captions[name] != caption: self.captionsTouched.add(name) self.captions[name] = caption if writeToFile: write_caption(self.files[name], caption)
def writeBackCaptions(self): for name in self.captionsTouched: write_caption(self.files[name], self.captions[name]) self.captionsTouched = set()