Commit 6c51da53 authored by Joel Collins's avatar Joel Collins
Browse files

Simplified build_captures_from_exif

parent c58827a0
Loading
Loading
Loading
Loading
Loading
+30 −36
Original line number Diff line number Diff line
@@ -60,9 +60,7 @@ def build_captures_from_exif(capture_path):

    for f in files:
        logging.debug("Reloading capture {}...".format(f))
        exif = pull_usercomment_dict(f)
        if exif:
            capture = capture_from_exif(f, exif)
        capture = capture_from_path(f)
        if capture:
            captures[capture.id] = capture
        else:
@@ -73,17 +71,9 @@ def build_captures_from_exif(capture_path):
    return captures


def capture_from_exif(path, exif_dict):
    """
    Creates an instance of CaptureObject from a dictionary of capture information.
    This is used when reloading the API server, to restore captures created in the 
    previous session.

    Args:
        path (str): Path to image file
        exif_dict (dict): Dictionary containing capture information
    """

def capture_from_path(path):
    exif_dict = pull_usercomment_dict(path)
    if exif_dict:
        # Create a placeholder capture
        capture = CaptureObject(filepath=path)

@@ -101,7 +91,9 @@ def capture_from_exif(path, exif_dict):

        # Populate capture parameters
        capture.id = image_metadata.get("id")
    capture.datetime = dateutil.parser.isoparse(image_metadata.get("acquisitionDate"))
        capture.datetime = dateutil.parser.isoparse(
            image_metadata.get("acquisitionDate")
        )
        capture.format = image_metadata.get("format")
        capture.tags = image_metadata.get("tags")
        capture.annotations = image_metadata.get("annotations")
@@ -110,6 +102,8 @@ def capture_from_exif(path, exif_dict):
        capture.set_metadata(exif_dict)

        return capture
    else:
        return None


class CaptureObject(object):