Renamed Resource to View, and allow custom root links
This commit is contained in:
parent
234ebc1cbb
commit
a329b9197b
18 changed files with 90 additions and 67 deletions
|
|
@ -79,16 +79,20 @@ for extension in find_extensions(USER_EXTENSIONS_PATH):
|
|||
|
||||
# Attach captures resources
|
||||
labthing.add_view(views.CaptureList, f"/captures")
|
||||
labthing.add_view(views.CaptureResource, f"/captures/<id>")
|
||||
labthing.add_root_link(views.CaptureList, "captures")
|
||||
|
||||
labthing.add_view(views.CaptureView, f"/captures/<id>")
|
||||
labthing.add_view(views.CaptureDownload, f"/captures/<id>/download/<filename>")
|
||||
labthing.add_view(views.CaptureTags, f"/captures/<id>/tags")
|
||||
labthing.add_view(views.CaptureMetadata, f"/captures/<id>/metadata")
|
||||
|
||||
# Attach settings and status resources
|
||||
labthing.add_view(views.SettingsProperty, f"/settings")
|
||||
labthing.add_root_link(views.SettingsProperty, "settings")
|
||||
labthing.add_view(views.NestedSettingsProperty, "/settings/<path:route>")
|
||||
labthing.add_view(views.StatusProperty, "/status")
|
||||
labthing.add_view(views.NestedStatusProperty, "/status/<path:route>")
|
||||
labthing.add_root_link(views.StatusProperty, "status")
|
||||
|
||||
# Attach streams resources
|
||||
labthing.add_view(views.MjpegStream, f"/streams/mjpeg")
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from openflexure_microscope.common.flask_labthings.find import find_component
|
||||
from openflexure_microscope.common.flask_labthings.extensions import BaseExtension
|
||||
from openflexure_microscope.common.flask_labthings.resource import Resource
|
||||
from openflexure_microscope.common.flask_labthings.view import View
|
||||
from openflexure_microscope.common.flask_labthings.decorators import (
|
||||
ThingAction,
|
||||
ThingProperty,
|
||||
|
|
@ -292,7 +292,7 @@ def fast_up_down_up_autofocus(
|
|||
return m.data_dict()
|
||||
|
||||
|
||||
class MeasureSharpnessAPI(Resource):
|
||||
class MeasureSharpnessAPI(View):
|
||||
def post(self):
|
||||
microscope = find_component("org.openflexure.microscope")
|
||||
|
||||
|
|
@ -303,7 +303,7 @@ class MeasureSharpnessAPI(Resource):
|
|||
|
||||
|
||||
@ThingAction
|
||||
class AutofocusAPI(Resource):
|
||||
class AutofocusAPI(View):
|
||||
"""
|
||||
Run a standard autofocus
|
||||
"""
|
||||
|
|
@ -330,7 +330,7 @@ class AutofocusAPI(Resource):
|
|||
|
||||
|
||||
@ThingAction
|
||||
class FastAutofocusAPI(Resource):
|
||||
class FastAutofocusAPI(View):
|
||||
"""
|
||||
Run a fast autofocus
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ from openflexure_microscope.common.flask_labthings import fields
|
|||
|
||||
from openflexure_microscope.devel import taskify, abort, update_task_progress
|
||||
|
||||
from openflexure_microscope.common.flask_labthings.resource import Resource
|
||||
from openflexure_microscope.common.flask_labthings.view import View
|
||||
import time
|
||||
|
||||
|
||||
|
|
@ -341,7 +341,7 @@ def stack(
|
|||
|
||||
|
||||
@ThingAction
|
||||
class TileScanAPI(Resource):
|
||||
class TileScanAPI(View):
|
||||
@use_args(
|
||||
{
|
||||
"filename": fields.String(),
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import tempfile
|
|||
import logging
|
||||
|
||||
from openflexure_microscope.common.flask_labthings.find import find_component
|
||||
from openflexure_microscope.common.flask_labthings.resource import Resource
|
||||
from openflexure_microscope.common.flask_labthings.view import View
|
||||
from openflexure_microscope.common.flask_labthings.extensions import BaseExtension
|
||||
from openflexure_microscope.common.flask_labthings.decorators import (
|
||||
ThingAction,
|
||||
|
|
@ -96,7 +96,7 @@ default_zip_manager = ZipManager()
|
|||
|
||||
|
||||
@ThingAction
|
||||
class ZipBuilderAPIView(Resource):
|
||||
class ZipBuilderAPIView(View):
|
||||
def post(self):
|
||||
|
||||
ids = list(JsonResponse(request).json)
|
||||
|
|
@ -109,12 +109,12 @@ class ZipBuilderAPIView(Resource):
|
|||
|
||||
|
||||
@ThingProperty
|
||||
class ZipListAPIView(Resource):
|
||||
class ZipListAPIView(View):
|
||||
def get(self):
|
||||
return jsonify(default_zip_manager.session_zips)
|
||||
|
||||
|
||||
class ZipGetterAPIView(Resource):
|
||||
class ZipGetterAPIView(View):
|
||||
def get(self, session_id):
|
||||
if not session_id in default_zip_manager.session_zips:
|
||||
return abort(404) # 404 Not Found
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from openflexure_microscope.common.flask_labthings.resource import Resource
|
||||
from openflexure_microscope.common.flask_labthings.view import View
|
||||
from openflexure_microscope.common.flask_labthings.extensions import BaseExtension
|
||||
from openflexure_microscope.common.flask_labthings.decorators import (
|
||||
ThingAction,
|
||||
|
|
@ -77,7 +77,7 @@ static_form = {
|
|||
|
||||
|
||||
@ThingProperty
|
||||
class TestAPIView(Resource):
|
||||
class TestAPIView(View):
|
||||
def get(self):
|
||||
global val_int
|
||||
val_int += 1
|
||||
|
|
@ -85,7 +85,7 @@ class TestAPIView(Resource):
|
|||
|
||||
|
||||
@ThingAction
|
||||
class TestDoAPIView(Resource):
|
||||
class TestDoAPIView(View):
|
||||
def post(self):
|
||||
global val_int
|
||||
val_int += 1
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from openflexure_microscope.api.utilities import get_bool, JsonResponse
|
||||
from openflexure_microscope.common.flask_labthings.resource import Resource
|
||||
from openflexure_microscope.common.flask_labthings.view import View
|
||||
from openflexure_microscope.common.flask_labthings.find import find_component
|
||||
from openflexure_microscope.common.flask_labthings.decorators import (
|
||||
use_args,
|
||||
|
|
@ -20,7 +20,7 @@ from flask import jsonify, request, abort, url_for, redirect, send_file
|
|||
|
||||
|
||||
@ThingAction
|
||||
class CaptureAPI(Resource):
|
||||
class CaptureAPI(View):
|
||||
"""
|
||||
Create a new image capture.
|
||||
"""
|
||||
|
|
@ -86,7 +86,7 @@ class CaptureAPI(Resource):
|
|||
|
||||
|
||||
@ThingAction
|
||||
class GPUPreviewStartAPI(Resource):
|
||||
class GPUPreviewStartAPI(View):
|
||||
"""
|
||||
Start the onboard GPU preview.
|
||||
Optional "window" parameter can be passed to control the position and size of the preview window,
|
||||
|
|
@ -119,7 +119,7 @@ class GPUPreviewStartAPI(Resource):
|
|||
|
||||
|
||||
@ThingAction
|
||||
class GPUPreviewStopAPI(Resource):
|
||||
class GPUPreviewStopAPI(View):
|
||||
def post(self):
|
||||
"""
|
||||
Stop the onboard GPU preview.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from openflexure_microscope.api.utilities import JsonResponse
|
||||
from openflexure_microscope.common.flask_labthings.resource import Resource
|
||||
from openflexure_microscope.common.flask_labthings.view import View
|
||||
from openflexure_microscope.common.flask_labthings.find import find_component
|
||||
from openflexure_microscope.common.flask_labthings.decorators import (
|
||||
use_args,
|
||||
|
|
@ -17,7 +17,7 @@ import logging
|
|||
|
||||
|
||||
@ThingAction
|
||||
class MoveStageAPI(Resource):
|
||||
class MoveStageAPI(View):
|
||||
@use_args(
|
||||
{
|
||||
"absolute": fields.Boolean(
|
||||
|
|
@ -62,7 +62,7 @@ class MoveStageAPI(Resource):
|
|||
|
||||
|
||||
@ThingAction
|
||||
class ZeroStageAPI(Resource):
|
||||
class ZeroStageAPI(View):
|
||||
def post(self):
|
||||
"""
|
||||
Zero the stage coordinates.
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from openflexure_microscope.common.flask_labthings.resource import Resource
|
||||
from openflexure_microscope.common.flask_labthings.view import View
|
||||
import subprocess
|
||||
import os
|
||||
from sys import platform
|
||||
|
|
@ -18,7 +18,7 @@ def is_raspberrypi(raise_on_errors=False):
|
|||
|
||||
|
||||
@ThingAction
|
||||
class ShutdownAPI(Resource):
|
||||
class ShutdownAPI(View):
|
||||
"""
|
||||
Attempt to shutdown the device
|
||||
"""
|
||||
|
|
@ -34,7 +34,7 @@ class ShutdownAPI(Resource):
|
|||
|
||||
|
||||
@ThingAction
|
||||
class RebootAPI(Resource):
|
||||
class RebootAPI(View):
|
||||
"""
|
||||
Attempt to reboot the device
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ from openflexure_microscope.api.utilities import get_bool, JsonResponse
|
|||
|
||||
from openflexure_microscope.common.flask_labthings.schema import Schema
|
||||
from openflexure_microscope.common.flask_labthings import fields
|
||||
from openflexure_microscope.common.flask_labthings.resource import Resource
|
||||
from openflexure_microscope.common.flask_labthings.view import View
|
||||
from openflexure_microscope.common.flask_labthings.utilities import (
|
||||
description_from_view,
|
||||
)
|
||||
|
|
@ -32,9 +32,9 @@ class CaptureSchema(Schema):
|
|||
def generate_links(self, data, **kwargs):
|
||||
data.links = {
|
||||
"self": {
|
||||
"href": url_for(CaptureResource.endpoint, id=data.id, _external=True),
|
||||
"href": url_for(CaptureView.endpoint, id=data.id, _external=True),
|
||||
"mimetype": "application/json",
|
||||
**description_from_view(CaptureResource),
|
||||
**description_from_view(CaptureView),
|
||||
},
|
||||
"tags": {
|
||||
"href": url_for(CaptureTags.endpoint, id=data.id, _external=True),
|
||||
|
|
@ -66,7 +66,7 @@ capture_list_schema = CaptureSchema(many=True)
|
|||
|
||||
@ThingProperty
|
||||
@Tag("captures")
|
||||
class CaptureList(Resource):
|
||||
class CaptureList(View):
|
||||
@marshal_with(CaptureSchema(many=True))
|
||||
def get(self):
|
||||
"""
|
||||
|
|
@ -78,7 +78,7 @@ class CaptureList(Resource):
|
|||
|
||||
|
||||
@Tag("captures")
|
||||
class CaptureResource(Resource):
|
||||
class CaptureView(View):
|
||||
@marshal_with(CaptureSchema())
|
||||
def get(self, id):
|
||||
"""
|
||||
|
|
@ -108,7 +108,7 @@ class CaptureResource(Resource):
|
|||
|
||||
|
||||
@Tag("captures")
|
||||
class CaptureDownload(Resource):
|
||||
class CaptureDownload(View):
|
||||
@doc_response(200, mimetype="image/jpeg")
|
||||
def get(self, id, filename):
|
||||
"""
|
||||
|
|
@ -144,7 +144,7 @@ class CaptureDownload(Resource):
|
|||
|
||||
|
||||
@Tag("captures")
|
||||
class CaptureTags(Resource):
|
||||
class CaptureTags(View):
|
||||
def get(self, id):
|
||||
"""
|
||||
Get tags associated with a single image capture
|
||||
|
|
@ -199,7 +199,7 @@ class CaptureTags(Resource):
|
|||
|
||||
|
||||
@Tag("captures")
|
||||
class CaptureMetadata(Resource):
|
||||
class CaptureMetadata(View):
|
||||
def get(self, id):
|
||||
"""
|
||||
Get metadata associated with a single image capture
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ from openflexure_microscope.common.labthings_core.utilities import (
|
|||
)
|
||||
|
||||
from openflexure_microscope.common.flask_labthings.find import find_component
|
||||
from openflexure_microscope.common.flask_labthings.resource import Resource
|
||||
from openflexure_microscope.common.flask_labthings.view import View
|
||||
|
||||
from openflexure_microscope.common.flask_labthings.decorators import ThingProperty, Tag, doc_response
|
||||
|
||||
|
|
@ -16,7 +16,7 @@ import logging
|
|||
|
||||
|
||||
@ThingProperty
|
||||
class SettingsProperty(Resource):
|
||||
class SettingsProperty(View):
|
||||
def get(self):
|
||||
"""
|
||||
Current microscope settings, including camera and stage
|
||||
|
|
@ -41,7 +41,7 @@ class SettingsProperty(Resource):
|
|||
|
||||
|
||||
@Tag("properties")
|
||||
class NestedSettingsProperty(Resource):
|
||||
class NestedSettingsProperty(View):
|
||||
@doc_response(404, description="Settings key cannot be found")
|
||||
def get(self, route):
|
||||
"""
|
||||
|
|
@ -76,7 +76,7 @@ class NestedSettingsProperty(Resource):
|
|||
|
||||
|
||||
@ThingProperty
|
||||
class StatusProperty(Resource):
|
||||
class StatusProperty(View):
|
||||
def get(self):
|
||||
"""
|
||||
Show current read-only state of the microscope
|
||||
|
|
@ -86,7 +86,7 @@ class StatusProperty(Resource):
|
|||
|
||||
|
||||
@Tag("properties")
|
||||
class NestedStatusProperty(Resource):
|
||||
class NestedStatusProperty(View):
|
||||
@doc_response(404, description="Status key cannot be found")
|
||||
def get(self, route):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -7,14 +7,14 @@ from openflexure_microscope.common.labthings_core.utilities import (
|
|||
)
|
||||
|
||||
from openflexure_microscope.common.flask_labthings.find import find_component
|
||||
from openflexure_microscope.common.flask_labthings.resource import Resource
|
||||
from openflexure_microscope.common.flask_labthings.view import View
|
||||
from openflexure_microscope.common.flask_labthings.decorators import doc_response, ThingProperty
|
||||
|
||||
from flask import Response
|
||||
|
||||
|
||||
@ThingProperty
|
||||
class MjpegStream(Resource):
|
||||
class MjpegStream(View):
|
||||
"""
|
||||
Real-time MJPEG stream from the microscope camera
|
||||
"""
|
||||
|
|
@ -34,7 +34,7 @@ class MjpegStream(Resource):
|
|||
|
||||
|
||||
@ThingProperty
|
||||
class SnapshotStream(Resource):
|
||||
class SnapshotStream(View):
|
||||
"""
|
||||
Single JPEG snapshot from the camera stream
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue