From 5dc838d5eb8c1fc54085290d07068c4e788eb550 Mon Sep 17 00:00:00 2001 From: Joel Collins Date: Mon, 15 Jun 2020 18:00:16 +0100 Subject: [PATCH] Added method to batch-write metadata parameters --- openflexure_microscope/captures/capture.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/openflexure_microscope/captures/capture.py b/openflexure_microscope/captures/capture.py index ed617236..0dc7b77b 100644 --- a/openflexure_microscope/captures/capture.py +++ b/openflexure_microscope/captures/capture.py @@ -246,6 +246,28 @@ class CaptureObject(object): self._metadata.update(data) self.save_metadata() + def put_and_save(self, tags: list = None, annotations: dict = None, metadata: dict = None): + """ + Batch-write tags, metadata, and annotations in a single disk operation + """ + if not tags: + tags = [] + if not annotations: + annotations = {} + if not metadata: + metadata = {} + + # Tags + for tag in tags: + if tag not in self.tags: + self.tags.append(tag) + # Annotations + self.annotations.update(annotations) + # Metadata + self._metadata.update(metadata) + + self.save_metadata + def save_metadata(self) -> None: """ Save metadata to exif, if supported