Minor tidy up
This commit is contained in:
parent
838c832272
commit
22665cde87
1 changed files with 7 additions and 10 deletions
|
|
@ -46,6 +46,7 @@ def uri(suffix, base=None):
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.url_map.strict_slashes = False
|
app.url_map.strict_slashes = False
|
||||||
|
|
||||||
|
|
||||||
# Make errors more API friendly
|
# Make errors more API friendly
|
||||||
|
|
||||||
def _handle_http_exception(e):
|
def _handle_http_exception(e):
|
||||||
|
|
@ -60,6 +61,7 @@ def _handle_http_exception(e):
|
||||||
for code in default_exceptions:
|
for code in default_exceptions:
|
||||||
app.errorhandler(code)(_handle_http_exception)
|
app.errorhandler(code)(_handle_http_exception)
|
||||||
|
|
||||||
|
|
||||||
# After app starts, but before first request, attach hardware to global microscope
|
# After app starts, but before first request, attach hardware to global microscope
|
||||||
@app.before_first_request
|
@app.before_first_request
|
||||||
def attach_microscope():
|
def attach_microscope():
|
||||||
|
|
@ -72,6 +74,7 @@ def attach_microscope():
|
||||||
)
|
)
|
||||||
logging.debug("Microscope successfully attached!")
|
logging.debug("Microscope successfully attached!")
|
||||||
|
|
||||||
|
|
||||||
##### WEBAPP ROUTES ######
|
##### WEBAPP ROUTES ######
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
|
|
@ -85,7 +88,9 @@ def index():
|
||||||
|
|
||||||
##### API ROUTES ######
|
##### API ROUTES ######
|
||||||
|
|
||||||
|
|
||||||
# Basic microscope view
|
# Basic microscope view
|
||||||
|
|
||||||
class MicroscopeView(MethodView):
|
class MicroscopeView(MethodView):
|
||||||
|
|
||||||
def __init__(self, microscope):
|
def __init__(self, microscope):
|
||||||
|
|
@ -98,8 +103,6 @@ class MicroscopeView(MethodView):
|
||||||
MethodView.__init__(self)
|
MethodView.__init__(self)
|
||||||
|
|
||||||
|
|
||||||
# State endpoints
|
|
||||||
|
|
||||||
class StreamAPI(MicroscopeView):
|
class StreamAPI(MicroscopeView):
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
|
|
@ -169,8 +172,6 @@ app.add_url_rule(
|
||||||
view_func=StateAPI.as_view('state', microscope=api_microscope))
|
view_func=StateAPI.as_view('state', microscope=api_microscope))
|
||||||
|
|
||||||
|
|
||||||
# Positioning endpoints
|
|
||||||
|
|
||||||
class PositionAPI(MicroscopeView):
|
class PositionAPI(MicroscopeView):
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
|
|
@ -243,7 +244,7 @@ class PositionAPI(MicroscopeView):
|
||||||
logging.debug(position)
|
logging.debug(position)
|
||||||
|
|
||||||
# Safeguard to prevent moving to an absolute position beyond a fixed limit
|
# Safeguard to prevent moving to an absolute position beyond a fixed limit
|
||||||
if not 'force' in state or state['force'] is False: # Allow for override
|
if 'force' not in state or state['force'] is False: # Allow for override
|
||||||
# TODO: Make travel_limit a property of the stage or microscope
|
# TODO: Make travel_limit a property of the stage or microscope
|
||||||
# TODO: Make travel_limit a 3-axis list
|
# TODO: Make travel_limit a 3-axis list
|
||||||
travel_limit = 20000
|
travel_limit = 20000
|
||||||
|
|
@ -262,8 +263,6 @@ app.add_url_rule(
|
||||||
view_func=PositionAPI.as_view('position', microscope=api_microscope))
|
view_func=PositionAPI.as_view('position', microscope=api_microscope))
|
||||||
|
|
||||||
|
|
||||||
# Capture endpoints
|
|
||||||
|
|
||||||
class CaptureListAPI(MicroscopeView):
|
class CaptureListAPI(MicroscopeView):
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
|
|
@ -372,8 +371,7 @@ class CaptureListAPI(MicroscopeView):
|
||||||
if 'width' in state['size'] and 'height' in state['size']:
|
if 'width' in state['size'] and 'height' in state['size']:
|
||||||
resize = (state['size']['width'], state['size']['height'])
|
resize = (state['size']['width'], state['size']['height'])
|
||||||
else:
|
else:
|
||||||
# TODO: Return error 4XX instead of exception
|
abort(400)
|
||||||
raise Exception("Invalid resize parameters passed. Ensure both width and height are specified.")
|
|
||||||
else:
|
else:
|
||||||
resize = None
|
resize = None
|
||||||
|
|
||||||
|
|
@ -519,7 +517,6 @@ class CaptureDownloadAPI(MicroscopeView):
|
||||||
:status 200: capture data found
|
:status 200: capture data found
|
||||||
:status 404: no capture found with that id
|
:status 404: no capture found with that id
|
||||||
"""
|
"""
|
||||||
print(capture_id)
|
|
||||||
capture_obj = self.microscope.camera.image_from_id(capture_id)
|
capture_obj = self.microscope.camera.image_from_id(capture_id)
|
||||||
|
|
||||||
if not capture_obj or not capture_obj.metadata['available']:
|
if not capture_obj or not capture_obj.metadata['available']:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue