Loading openflexure_microscope/api/app.py +2 −2 Original line number Diff line number Diff line Loading @@ -148,8 +148,8 @@ app.register_blueprint(task_blueprint, url_prefix=uri("/task", "v1")) v2_root_blueprint = v2.blueprints.root.construct_blueprint(api_microscope) app.register_blueprint(v2_root_blueprint, url_prefix=uri("/", "v2")) v2_stream_blueprint = v2.blueprints.stream.construct_blueprint(api_microscope) app.register_blueprint(v2_stream_blueprint, url_prefix=uri("/", "v2")) v2_streams_blueprint = v2.blueprints.streams.construct_blueprint(api_microscope) app.register_blueprint(v2_streams_blueprint, url_prefix=uri("/streams", "v2")) # Captures routes v2_captures_blueprint = v2.blueprints.captures.construct_blueprint(api_microscope) Loading openflexure_microscope/api/v2/blueprints/__init__.py +1 −1 Original line number Diff line number Diff line from . import root, captures, settings, status, tasks, stream, plugins, actions from . import root, captures, settings, status, tasks, streams, plugins, actions openflexure_microscope/api/v2/blueprints/actions/__init__.py +5 −3 Original line number Diff line number Diff line Loading @@ -11,6 +11,11 @@ from openflexure_microscope.api.views import MicroscopeView from . import camera, stage, system class ActionsAPI(MicroscopeView): def get(self): return jsonify(actions_representation()) _actions = { "capture": { "rule": "/camera/capture/", Loading Loading @@ -67,9 +72,6 @@ def actions_representation(): return actions class ActionsAPI(MicroscopeView): def get(self): return jsonify(actions_representation()) def construct_blueprint(microscope_obj): global _actions Loading openflexure_microscope/api/v2/blueprints/root.py +2 −2 Original line number Diff line number Diff line Loading @@ -4,10 +4,10 @@ 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, stream 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, stream] _root_blueprint_modules = [settings, status, plugins, captures, actions, streams] def root_representation(): """ Loading openflexure_microscope/api/v2/blueprints/stream.py→openflexure_microscope/api/v2/blueprints/streams.py +59 −5 Original line number Diff line number Diff line """ 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 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 from flask import Response, Blueprint, jsonify, request, url_for class StreamAPI(MicroscopeView): def get(self): return jsonify(streams_representation()) class MjpegAPI(MicroscopeView): """ Real-time MJPEG stream from the microscope camera """ def get(self): """ Real-time MJPEG stream from the microscope camera Loading @@ -26,6 +39,9 @@ class StreamAPI(MicroscopeView): class SnapshotAPI(MicroscopeView): """ Single JPEG snapshot from the camera stream """ def get(self): """ Single snapshot from the camera stream Loading @@ -42,17 +58,55 @@ class SnapshotAPI(MicroscopeView): return Response(self.microscope.camera.get_frame(), mimetype="image/jpeg") _streams = { "mjpeg": { "rule": "/mjpeg", "view_class": MjpegAPI, "conditions": True, }, "snapshot": { "rule": "/snapshot", "view_class": SnapshotAPI, "conditions": True, } } def enabled_streams(): global _streams return {k: v for k, v in _streams.items() if v["conditions"]} def streams_representation(): global _streams streams = {} for name, stream in enabled_streams().items(): d = { "links": {"self": url_for(f".{name}")}, } d.update(description_from_view(stream["view_class"])) streams[name] = d return streams def construct_blueprint(microscope_obj): blueprint = blueprint_for_module(__name__) # For each enabled stream route defined in our dictionary above for name, stream in enabled_streams().items(): # Add the action to our blueprint blueprint.add_url_rule( "/stream", view_func=StreamAPI.as_view("stream", microscope=microscope_obj) stream["rule"], view_func=stream["view_class"].as_view(name, microscope=microscope_obj), ) blueprint.add_url_rule( "/snapshot", view_func=SnapshotAPI.as_view("snapshot", microscope=microscope_obj), "/", view_func=StreamAPI.as_view("streams", microscope=microscope_obj) ) return blueprint Loading
openflexure_microscope/api/app.py +2 −2 Original line number Diff line number Diff line Loading @@ -148,8 +148,8 @@ app.register_blueprint(task_blueprint, url_prefix=uri("/task", "v1")) v2_root_blueprint = v2.blueprints.root.construct_blueprint(api_microscope) app.register_blueprint(v2_root_blueprint, url_prefix=uri("/", "v2")) v2_stream_blueprint = v2.blueprints.stream.construct_blueprint(api_microscope) app.register_blueprint(v2_stream_blueprint, url_prefix=uri("/", "v2")) v2_streams_blueprint = v2.blueprints.streams.construct_blueprint(api_microscope) app.register_blueprint(v2_streams_blueprint, url_prefix=uri("/streams", "v2")) # Captures routes v2_captures_blueprint = v2.blueprints.captures.construct_blueprint(api_microscope) Loading
openflexure_microscope/api/v2/blueprints/__init__.py +1 −1 Original line number Diff line number Diff line from . import root, captures, settings, status, tasks, stream, plugins, actions from . import root, captures, settings, status, tasks, streams, plugins, actions
openflexure_microscope/api/v2/blueprints/actions/__init__.py +5 −3 Original line number Diff line number Diff line Loading @@ -11,6 +11,11 @@ from openflexure_microscope.api.views import MicroscopeView from . import camera, stage, system class ActionsAPI(MicroscopeView): def get(self): return jsonify(actions_representation()) _actions = { "capture": { "rule": "/camera/capture/", Loading Loading @@ -67,9 +72,6 @@ def actions_representation(): return actions class ActionsAPI(MicroscopeView): def get(self): return jsonify(actions_representation()) def construct_blueprint(microscope_obj): global _actions Loading
openflexure_microscope/api/v2/blueprints/root.py +2 −2 Original line number Diff line number Diff line Loading @@ -4,10 +4,10 @@ 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, stream 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, stream] _root_blueprint_modules = [settings, status, plugins, captures, actions, streams] def root_representation(): """ Loading
openflexure_microscope/api/v2/blueprints/stream.py→openflexure_microscope/api/v2/blueprints/streams.py +59 −5 Original line number Diff line number Diff line """ 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 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 from flask import Response, Blueprint, jsonify, request, url_for class StreamAPI(MicroscopeView): def get(self): return jsonify(streams_representation()) class MjpegAPI(MicroscopeView): """ Real-time MJPEG stream from the microscope camera """ def get(self): """ Real-time MJPEG stream from the microscope camera Loading @@ -26,6 +39,9 @@ class StreamAPI(MicroscopeView): class SnapshotAPI(MicroscopeView): """ Single JPEG snapshot from the camera stream """ def get(self): """ Single snapshot from the camera stream Loading @@ -42,17 +58,55 @@ class SnapshotAPI(MicroscopeView): return Response(self.microscope.camera.get_frame(), mimetype="image/jpeg") _streams = { "mjpeg": { "rule": "/mjpeg", "view_class": MjpegAPI, "conditions": True, }, "snapshot": { "rule": "/snapshot", "view_class": SnapshotAPI, "conditions": True, } } def enabled_streams(): global _streams return {k: v for k, v in _streams.items() if v["conditions"]} def streams_representation(): global _streams streams = {} for name, stream in enabled_streams().items(): d = { "links": {"self": url_for(f".{name}")}, } d.update(description_from_view(stream["view_class"])) streams[name] = d return streams def construct_blueprint(microscope_obj): blueprint = blueprint_for_module(__name__) # For each enabled stream route defined in our dictionary above for name, stream in enabled_streams().items(): # Add the action to our blueprint blueprint.add_url_rule( "/stream", view_func=StreamAPI.as_view("stream", microscope=microscope_obj) stream["rule"], view_func=stream["view_class"].as_view(name, microscope=microscope_obj), ) blueprint.add_url_rule( "/snapshot", view_func=SnapshotAPI.as_view("snapshot", microscope=microscope_obj), "/", view_func=StreamAPI.as_view("streams", microscope=microscope_obj) ) return blueprint