Restructured labthings
This commit is contained in:
parent
206dd521ec
commit
a8a3cafa97
39 changed files with 275 additions and 269 deletions
50
openflexure_microscope/common/flask_labthings/find.py
Normal file
50
openflexure_microscope/common/flask_labthings/find.py
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import logging
|
||||
from flask import current_app
|
||||
|
||||
from . import EXTENSION_NAME
|
||||
|
||||
|
||||
def current_labthing():
|
||||
app = current_app._get_current_object()
|
||||
if not app:
|
||||
return None
|
||||
logging.debug("Active app extensions:")
|
||||
logging.debug(app.extensions)
|
||||
logging.debug("Active labthing:")
|
||||
logging.debug(app.extensions[EXTENSION_NAME])
|
||||
return app.extensions[EXTENSION_NAME]
|
||||
|
||||
|
||||
def registered_plugins(labthing_instance=None):
|
||||
if not labthing_instance:
|
||||
labthing_instance = current_labthing()
|
||||
return labthing_instance.plugins
|
||||
|
||||
|
||||
def registered_devices(labthing_instance=None):
|
||||
if not labthing_instance:
|
||||
labthing_instance = current_labthing()
|
||||
return labthing_instance.devices
|
||||
|
||||
|
||||
def find_device(device_name, labthing_instance=None):
|
||||
if not labthing_instance:
|
||||
labthing_instance = current_labthing()
|
||||
|
||||
if device_name in labthing_instance.devices:
|
||||
return labthing_instance.devices[device_name]
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
def find_plugin(plugin_name, labthing_instance=None):
|
||||
if not labthing_instance:
|
||||
labthing_instance = current_labthing()
|
||||
|
||||
logging.debug("Current labthing:")
|
||||
logging.debug(current_labthing())
|
||||
|
||||
if plugin_name in labthing_instance.plugins:
|
||||
return labthing_instance.plugins[plugin_name]
|
||||
else:
|
||||
return None
|
||||
Loading…
Add table
Add a link
Reference in a new issue