Blackened

This commit is contained in:
Joel Collins 2019-11-20 14:13:01 +00:00
parent 36f195d6e7
commit b430a2d34a
15 changed files with 72 additions and 54 deletions

View file

@ -2,13 +2,19 @@ import logging
from werkzeug.exceptions import BadRequest
from flask import url_for, Blueprint
def blueprint_for_module(module_name, api_ver=2, suffix=""):
return Blueprint(blueprint_name_for_module(module_name, api_ver=api_ver, suffix=suffix), module_name)
return Blueprint(
blueprint_name_for_module(module_name, api_ver=api_ver, suffix=suffix),
module_name,
)
def blueprint_name_for_module(module_name, api_ver=2, suffix=""):
bp_name = module_name.split('.')[-1]
bp_name = module_name.split(".")[-1]
return f"v{api_ver}_{bp_name}_blueprint{suffix}"
class JsonResponse:
def __init__(self, request):
"""

View file

@ -11,6 +11,7 @@ from openflexure_microscope.api.views import MicroscopeView
from . import camera, stage, system
class ActionsAPI(MicroscopeView):
def get(self):
return jsonify(actions_representation())

View file

@ -10,6 +10,7 @@ class CaptureAPI(MicroscopeView):
"""
Create a new image capture.
"""
def post(self):
"""
Create a new image capture.
@ -107,6 +108,7 @@ class GPUPreviewStartAPI(MicroscopeView):
"""
Start the onboard GPU preview.
"""
def post(self, operation):
"""
Start the onboard GPU preview.
@ -152,6 +154,7 @@ class GPUPreviewStopAPI(MicroscopeView):
"""
Stop the onboard GPU preview.
"""
def post(self, operation):
"""
Stop the onboard GPU preview.

View file

@ -11,6 +11,7 @@ class MoveStageAPI(MicroscopeView):
"""
Handle stage movements.
"""
def post(self):
"""
Set x, y and z positions of the stage.

View file

@ -7,6 +7,7 @@ class ShutdownAPI(MicroscopeView):
"""
Attempt to shutdown the device
"""
def post(self):
"""
Attempt to shutdown the device
@ -23,6 +24,7 @@ class RebootAPI(MicroscopeView):
"""
Attempt to reboot the device
"""
def post(self):
"""
Attempt to shutdown the device

View file

@ -383,7 +383,7 @@ class TagsAPI(MicroscopeView):
def construct_blueprint(microscope_obj):
blueprint = blueprint_for_module(__name__)
# Tag routes

View file

@ -14,6 +14,7 @@ import copy
import logging
import warnings
def plugins_representation(plugin_loader_object: PluginLoader):
"""
Generate a dictionary representation of all plugins, including Flask route URLs
@ -33,16 +34,14 @@ def plugins_representation(plugin_loader_object: PluginLoader):
"plugin": str(plugin),
"views": {},
"gui": plugin.gui,
"description": get_docstring(plugin)
"description": get_docstring(plugin),
}
for view_id, view_data in plugin.views.items():
logging.debug(f"Representing view {view_id}")
uri = url_for(f"v2_plugins_blueprint.{view_id}")
# Make links dictionary if it doesn't yet exist
view_d = {
"links": {"self": uri}
}
view_d = {"links": {"self": uri}}
view_d.update(description_from_view(view_data["view"]))
@ -87,9 +86,7 @@ def construct_blueprint(microscope_obj):
blueprint.add_url_rule(
plugin_view["rule"],
view_func=plugin_view["view"].as_view(
plugin_view_id,
microscope=microscope_obj,
plugin=plugin,
plugin_view_id, microscope=microscope_obj, plugin=plugin
),
)

View file

@ -4,11 +4,19 @@ from openflexure_microscope.api.views import MicroscopeView
from openflexure_microscope.utilities import get_docstring, bottom_level_name
from openflexure_microscope.api.utilities import blueprint_name_for_module
from openflexure_microscope.api.v2.blueprints import settings, status, plugins, captures, actions, streams
from openflexure_microscope.api.v2.blueprints import (
settings,
status,
plugins,
captures,
actions,
streams,
)
# List of submodules containing create_blueprint methods using standard blueprint_for_module naming
_root_blueprint_modules = [settings, status, plugins, captures, actions, streams]
def root_representation():
"""
Generate a dictionar representation of all top-level blueprint rules
@ -23,7 +31,7 @@ def root_representation():
d[module_short_name] = {
"name": blueprint_module.__name__,
"description": get_docstring(blueprint_module),
"links": {"self": url_for(f"{blueprint_name}.{module_short_name}")}
"links": {"self": url_for(f"{blueprint_name}.{module_short_name}")},
}
return d

View file

@ -7,6 +7,7 @@ from openflexure_microscope.api.utilities import blueprint_for_module
from flask import Blueprint, jsonify
class StatusAPI(MicroscopeView):
def get(self):
"""

View file

@ -4,7 +4,10 @@ Top-level description of routes related to live camera stream data
from openflexure_microscope.api.utilities import gen, JsonResponse
from openflexure_microscope.api.views import MicroscopeView
from openflexure_microscope.api.utilities import blueprint_for_module, blueprint_name_for_module
from openflexure_microscope.api.utilities import (
blueprint_for_module,
blueprint_name_for_module,
)
from openflexure_microscope.utilities import description_from_view
from flask import Response, Blueprint, jsonify, request, url_for
@ -19,6 +22,7 @@ class MjpegAPI(MicroscopeView):
"""
Real-time MJPEG stream from the microscope camera
"""
def get(self):
"""
Real-time MJPEG stream from the microscope camera
@ -42,6 +46,7 @@ class SnapshotAPI(MicroscopeView):
"""
Single JPEG snapshot from the camera stream
"""
def get(self):
"""
Single snapshot from the camera stream
@ -59,16 +64,8 @@ class SnapshotAPI(MicroscopeView):
_streams = {
"mjpeg": {
"rule": "/mjpeg",
"view_class": MjpegAPI,
"conditions": True,
},
"snapshot": {
"rule": "/snapshot",
"view_class": SnapshotAPI,
"conditions": True,
}
"mjpeg": {"rule": "/mjpeg", "view_class": MjpegAPI, "conditions": True},
"snapshot": {"rule": "/snapshot", "view_class": SnapshotAPI, "conditions": True},
}
@ -82,9 +79,7 @@ def streams_representation():
streams = {}
for name, stream in enabled_streams().items():
d = {
"links": {"self": url_for(f".{name}")},
}
d = {"links": {"self": url_for(f".{name}")}}
d.update(description_from_view(stream["view_class"]))