Commit bf9a1e35 authored by Joel Collins's avatar Joel Collins
Browse files

Fixed finding captures by UUID

parent 0f16c5c8
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@ import logging
from abc import ABCMeta, abstractmethod

from .capture import CaptureObject
from openflexure_microscope.utilities import entry_by_id
from openflexure_microscope.utilities import entry_by_uuid
from openflexure_microscope.common.labthings_core.lock import StrictLock


@@ -250,11 +250,11 @@ class BaseCamera(metaclass=ABCMeta):

    def image_from_id(self, image_id):
        """Return an image StreamObject with a matching ID."""
        return entry_by_id(image_id, self.images)
        return entry_by_uuid(image_id, self.images)

    def video_from_id(self, video_id):
        """Return a video StreamObject with a matching ID."""
        return entry_by_id(video_id, self.videos)
        return entry_by_uuid(video_id, self.videos)

    # CREATING NEW CAPTURES

+12 −2
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ import re
import copy
import operator
import base64
from uuid import UUID
import numpy as np
from collections import abc
from functools import reduce
@@ -78,11 +79,20 @@ def filter_dict(dictionary: dict, keys: list):
    return out


def entry_by_id(entry_id: str, object_list: list):
def entry_by_uuid(entry_id: str, object_list: list):
    """Return an object from a list, if <object>.id matches id argument."""
    found = None
    if type(entry_id) == str:
        converter = str
    elif type(entry_id) == int:
        converter = int
    elif isinstance(entry_id, UUID):
        converter = int
    else:
        raise TypeError("Argument entry_id must be a string, integer, or UUID object.")
    for o in object_list:
        if o.id == entry_id:
        # Convert to strings (in case of UUID objects, for example)
        if converter(o.id) == converter(entry_id):
            found = o
    return found