Implemented root API v2 routes
This commit is contained in:
parent
5aa783c269
commit
6581612312
27 changed files with 1205 additions and 148 deletions
|
|
@ -3,7 +3,7 @@ __all__ = [
|
|||
"load_plugin_class",
|
||||
"load_plugin_module",
|
||||
"class_from_map",
|
||||
"PluginMount",
|
||||
"PluginLoader",
|
||||
"MicroscopePlugin",
|
||||
]
|
||||
|
||||
|
|
@ -12,6 +12,6 @@ from .loader import (
|
|||
load_plugin_class,
|
||||
load_plugin_module,
|
||||
class_from_map,
|
||||
PluginMount,
|
||||
PluginLoader,
|
||||
MicroscopePlugin,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -37,10 +37,10 @@ class Plugin(MicroscopePlugin):
|
|||
"""
|
||||
scamera = self.microscope.camera
|
||||
with scamera.lock:
|
||||
assert not scamera.state[
|
||||
assert not scamera.status[
|
||||
"record_active"
|
||||
], "Can't recalibrate while recording!"
|
||||
streaming = scamera.state["stream_active"]
|
||||
streaming = scamera.status["stream_active"]
|
||||
if streaming:
|
||||
logging.info("Stopping stream before recalibration")
|
||||
scamera.stop_stream_recording(resolution=(640, 480))
|
||||
|
|
@ -51,7 +51,7 @@ class Plugin(MicroscopePlugin):
|
|||
recalibrate_camera(scamera.camera)
|
||||
finally:
|
||||
scamera.camera.resolution = old_resolution
|
||||
self.microscope.save_config()
|
||||
self.microscope.save_settings()
|
||||
if streaming:
|
||||
logging.info("Restarting stream after recalibration")
|
||||
scamera.start_stream_recording()
|
||||
|
|
|
|||
|
|
@ -97,18 +97,19 @@ class ScanPlugin(MicroscopePlugin):
|
|||
if "scan" not in tags:
|
||||
tags.append("scan")
|
||||
|
||||
metadata.update(
|
||||
{
|
||||
"scan_id": scan_id,
|
||||
"basename": basename,
|
||||
"microscope_settings": self.microscope.read_config(),
|
||||
"microscope_state": self.microscope.state,
|
||||
"microscope_id": self.microscope.id,
|
||||
"microscope_name": self.microscope.name,
|
||||
}
|
||||
)
|
||||
# Inject system metadata
|
||||
system_metadata = {
|
||||
"microscope_settings": self.microscope.read_settings(),
|
||||
"microscope_state": self.microscope.state,
|
||||
"microscope_id": self.microscope.id,
|
||||
"microscope_name": self.microscope.name,
|
||||
}
|
||||
output.system_metadata.update(system_metadata)
|
||||
|
||||
# Insert custom metadata
|
||||
output.put_metadata(metadata)
|
||||
|
||||
# Insert custom tags
|
||||
output.put_tags(tags)
|
||||
|
||||
def tile(
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ def class_from_map(plugin_map):
|
|||
return load_plugin_class(*plugin_arr)
|
||||
|
||||
|
||||
class PluginMount(object):
|
||||
class PluginLoader(object):
|
||||
"""
|
||||
A mount-point for all loaded plugins. Attaches to a Microscope object.
|
||||
|
||||
|
|
@ -147,30 +147,19 @@ class PluginMount(object):
|
|||
|
||||
def __init__(self, parent):
|
||||
self.parent = parent
|
||||
self.plugins = [] # List of plugin objects
|
||||
self._plugins = [] # List of plugin objects
|
||||
self.forms = [] # List of plugin forms
|
||||
logging.info("Creating plugin mount")
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
return [m[0] for m in self.members]
|
||||
# DEPRECATED
|
||||
logging.warning("PluginMount.state is deprecated. Use PluginMount.active instead. State will be removed in a future version.")
|
||||
return [m["python_name"] for m in self._plugins]
|
||||
|
||||
@property
|
||||
def members(self):
|
||||
ignores = ["state", "members", "attach"]
|
||||
plugin_array = []
|
||||
for obj_name in dir(self):
|
||||
if not obj_name in ignores and not obj_name[:2] == "__":
|
||||
obj = getattr(self, obj_name)
|
||||
if isinstance(obj, MicroscopePlugin):
|
||||
plugin_members = [
|
||||
member
|
||||
for member in inspect.getmembers(obj)
|
||||
if not member[0][:2] == "__"
|
||||
]
|
||||
plugin_info = (obj_name, plugin_members)
|
||||
plugin_array.append(plugin_info)
|
||||
return plugin_array
|
||||
def active(self):
|
||||
return self._plugins
|
||||
|
||||
def attach(self, plugin_map):
|
||||
"""
|
||||
|
|
@ -204,7 +193,15 @@ class PluginMount(object):
|
|||
): # If plugin_object is an instance of MicroscopePlugin
|
||||
# Attach plugin_object to the plugin mount
|
||||
setattr(self, pythonsafe_plugin_name, plugin_object)
|
||||
self.plugins.append((plugin_name, plugin_object))
|
||||
|
||||
# Store the plugin object, and it's properties
|
||||
self._plugins.append({
|
||||
"name": plugin_name,
|
||||
"python_name": pythonsafe_plugin_name,
|
||||
"plugin": plugin_object,
|
||||
"routes": [],
|
||||
"form": None
|
||||
})
|
||||
|
||||
# Grant plugin access to the hardware
|
||||
plugin_object.microscope = self.parent
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue