Some minor type fixes
This commit is contained in:
parent
58aa3df587
commit
141ccc06c1
3 changed files with 12 additions and 6 deletions
|
|
@ -14,12 +14,13 @@ output to STDOUT/STDERR are captured by ``systemd``. These can be viewed by usin
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
from logging.handlers import RotatingFileHandler
|
from logging.handlers import RotatingFileHandler
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from fastapi import HTTPException
|
from fastapi import HTTPException
|
||||||
from fastapi.responses import PlainTextResponse
|
from fastapi.responses import PlainTextResponse
|
||||||
|
|
||||||
LOGGER = logging.getLogger(__name__)
|
LOGGER = logging.getLogger(__name__)
|
||||||
OFM_LOG_FILE = None
|
OFM_LOG_FILE: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
def configure_logging(log_folder: str) -> None:
|
def configure_logging(log_folder: str) -> None:
|
||||||
|
|
@ -128,7 +129,7 @@ class OFMHandler(logging.Handler):
|
||||||
how many can be returned over HTTP.
|
how many can be returned over HTTP.
|
||||||
"""
|
"""
|
||||||
super().__init__(level=level)
|
super().__init__(level=level)
|
||||||
self._log = []
|
self._log: list[str] = []
|
||||||
self._max_logs = max_logs
|
self._max_logs = max_logs
|
||||||
|
|
||||||
def append_record(self, record: logging.LogRecord) -> None:
|
def append_record(self, record: logging.LogRecord) -> None:
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ from fastapi import Response
|
||||||
|
|
||||||
import labthings_fastapi as lt
|
import labthings_fastapi as lt
|
||||||
|
|
||||||
|
from openflexure_microscope_server.things.camera import BaseCamera
|
||||||
|
|
||||||
FAKE_ROUTES = [
|
FAKE_ROUTES = [
|
||||||
"/api/v2/",
|
"/api/v2/",
|
||||||
"/api/v2/streams/snapshot",
|
"/api/v2/streams/snapshot",
|
||||||
|
|
@ -38,7 +40,10 @@ def add_v2_endpoints(thing_server: lt.ThingServer) -> None:
|
||||||
@app.head("/api/v2/streams/snapshot")
|
@app.head("/api/v2/streams/snapshot")
|
||||||
async def thumbnail() -> JPEGResponse:
|
async def thumbnail() -> JPEGResponse:
|
||||||
"""Return a low-resolution snapshot, for compatibility with OF connect."""
|
"""Return a low-resolution snapshot, for compatibility with OF connect."""
|
||||||
blob = await thing_server.things["camera"].lores_mjpeg_stream.grab_frame()
|
camera_thing = thing_server.things["camera"]
|
||||||
|
if not isinstance(camera_thing, BaseCamera):
|
||||||
|
raise RuntimeError("Camera thing is not a BaseCamera")
|
||||||
|
blob = await camera_thing.lores_mjpeg_stream.grab_frame()
|
||||||
return JPEGResponse(blob)
|
return JPEGResponse(blob)
|
||||||
|
|
||||||
@app.get("/api/v2/instrument/settings/name")
|
@app.get("/api/v2/instrument/settings/name")
|
||||||
|
|
|
||||||
|
|
@ -272,7 +272,7 @@ class BaseCamera(lt.Thing):
|
||||||
@lt.action
|
@lt.action
|
||||||
def capture_jpeg(
|
def capture_jpeg(
|
||||||
self,
|
self,
|
||||||
stream_name: str = "main",
|
stream_name: Literal["main", "lores", "full"] = "main",
|
||||||
wait: Optional[float] = None,
|
wait: Optional[float] = None,
|
||||||
) -> JPEGBlob:
|
) -> JPEGBlob:
|
||||||
"""Acquire one image from the camera as a JPEG.
|
"""Acquire one image from the camera as a JPEG.
|
||||||
|
|
@ -526,7 +526,7 @@ class BaseCamera(lt.Thing):
|
||||||
nothing is returned on success
|
nothing is returned on success
|
||||||
"""
|
"""
|
||||||
if save_resolution is not None and image.size != save_resolution:
|
if save_resolution is not None and image.size != save_resolution:
|
||||||
image = image.resize(save_resolution, Image.BOX)
|
image = image.resize(save_resolution, Image.Resampling.BOX)
|
||||||
try:
|
try:
|
||||||
# Per PIL documentation,
|
# Per PIL documentation,
|
||||||
# (https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html#jpeg)
|
# (https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html#jpeg)
|
||||||
|
|
@ -537,7 +537,7 @@ class BaseCamera(lt.Thing):
|
||||||
# disabled, file size increases and quality is barely or not affected
|
# disabled, file size increases and quality is barely or not affected
|
||||||
image.save(jpeg_path, quality=95, subsampling=0)
|
image.save(jpeg_path, quality=95, subsampling=0)
|
||||||
try:
|
try:
|
||||||
self._add_metadata_to_capture(jpeg_path, metadata)
|
self._add_metadata_to_capture(jpeg_path, dict(metadata))
|
||||||
except Exception:
|
except Exception:
|
||||||
# We need to capture any exception as there are many reasons metadata
|
# We need to capture any exception as there are many reasons metadata
|
||||||
# might not be added. We warn rather than log the error.
|
# might not be added. We warn rather than log the error.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue