Moved plugins up one level and added new view plugins

This commit is contained in:
Joel Collins 2018-12-12 14:58:55 +00:00
parent ac5f26ef6b
commit bde2e9de2a
7 changed files with 53 additions and 36 deletions

View file

@ -0,0 +1 @@
from .plugin import Plugin

View file

@ -0,0 +1,20 @@
from openflexure_microscope.api.utilities import parse_payload
from openflexure_microscope.api.v1.views import MicroscopeViewPlugin
from flask import request, Response, escape
import logging
class IdentifyAPI(MicroscopeViewPlugin):
def get(self):
data = self.microscope.plugin.default.identify() # Call a method from our plugin, using the full route
return Response(escape(data))
class HelloWorldAPI(MicroscopeViewPlugin):
def get(self):
data = self.plugin.hello_world() # Call a method from our plugin, using the MicroscopeViewPlugin.plugin shortcut
return Response(data)

View file

@ -0,0 +1,30 @@
from openflexure_microscope.plugins import MicroscopePlugin
from .api import IdentifyAPI, HelloWorldAPI
class Plugin(MicroscopePlugin):
"""
A set of default plugins
"""
api_views = {
'/identify': IdentifyAPI,
'/hello': HelloWorldAPI,
}
def identify(self):
"""
Demonstrate access to Microscope.camera, and Microscope.stage
"""
response = "My parent camera is {}, and my parent stage is {}.".format(self.microscope.camera, self.microscope.stage)
print(response)
return response
def hello_world(self):
"""
Demonstrate passive method
"""
return "Hello world!"

View file

@ -1,2 +0,0 @@
from openflexure_microscope.plugins.default.test_plugin.api import ENDPOINTS
from openflexure_microscope.plugins.default.test_plugin.plugin import PLUGINS

View file

@ -1,28 +0,0 @@
from openflexure_microscope.api.utilities import parse_payload
from openflexure_microscope.api.v1.views import MicroscopeView
from flask import request, Response
import logging
class PluginTestAPI(MicroscopeView):
def get(self):
data = self.microscope.plugin.test1.run() # Call a method from our plugin
return Response(data)
def post(self):
# Get payload
state = parse_payload(request)
logging.debug(state)
# Handle absolute positioning
if 'data' in state: # If value is given in payload JSON
data = str(state['data']) # Process and store that value
return Response(data)
ENDPOINTS = {
'test1': PluginTestAPI
}

View file

@ -0,0 +1 @@
from .plugin import FirstPlugin

View file

@ -11,9 +11,4 @@ class FirstPlugin(MicroscopePlugin):
"""
response = "My parent camera is {}, and my parent stage is {}.".format(self.microscope.camera, self.microscope.stage)
return response
PLUGINS = {
'test1': FirstPlugin,
} #: dict: Dictionary describing the plugins. Keys are the names of the plugin's namescape, with a value corresponding to the class of that plugin.
return response