Tidied and improved JSON representations
This commit is contained in:
parent
d79fd55301
commit
0907d013cd
6 changed files with 10 additions and 19 deletions
|
|
@ -45,7 +45,6 @@ _actions = {
|
||||||
|
|
||||||
def enabled_actions():
|
def enabled_actions():
|
||||||
global _actions
|
global _actions
|
||||||
|
|
||||||
return {k: v for k, v in _actions.items() if v["conditions"]}
|
return {k: v for k, v in _actions.items() if v["conditions"]}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -53,7 +52,6 @@ def actions_representation():
|
||||||
global _actions
|
global _actions
|
||||||
|
|
||||||
actions = {}
|
actions = {}
|
||||||
|
|
||||||
for name, action in enabled_actions().items():
|
for name, action in enabled_actions().items():
|
||||||
d = {
|
d = {
|
||||||
"links": {"self": url_for(f".{name}")},
|
"links": {"self": url_for(f".{name}")},
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,8 @@
|
||||||
from openflexure_microscope.api.views import MicroscopeView
|
from openflexure_microscope.api.views import MicroscopeView
|
||||||
|
|
||||||
from flask import jsonify
|
|
||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import logging
|
|
||||||
|
|
||||||
|
|
||||||
# TODO: Make robust against different host OS
|
|
||||||
class ShutdownAPI(MicroscopeView):
|
class ShutdownAPI(MicroscopeView):
|
||||||
def post(self):
|
def post(self):
|
||||||
"""
|
"""
|
||||||
|
|
@ -17,7 +13,7 @@ class ShutdownAPI(MicroscopeView):
|
||||||
"""
|
"""
|
||||||
subprocess.Popen(['shutdown', '-h', 'now'])
|
subprocess.Popen(['shutdown', '-h', 'now'])
|
||||||
|
|
||||||
return '', 202
|
return "{}", 201
|
||||||
|
|
||||||
|
|
||||||
class RebootAPI(MicroscopeView):
|
class RebootAPI(MicroscopeView):
|
||||||
|
|
@ -30,4 +26,4 @@ class RebootAPI(MicroscopeView):
|
||||||
"""
|
"""
|
||||||
subprocess.Popen(['sudo', 'shutdown', '-r', 'now'])
|
subprocess.Popen(['sudo', 'shutdown', '-r', 'now'])
|
||||||
|
|
||||||
return '', 202
|
return "{}", 201
|
||||||
|
|
|
||||||
|
|
@ -61,9 +61,7 @@ class ListAPI(MicroscopeView):
|
||||||
:status 200: capture found
|
:status 200: capture found
|
||||||
:status 404: no capture found with that id
|
:status 404: no capture found with that id
|
||||||
"""
|
"""
|
||||||
include_unavailable = get_bool(request.args.get("include_unavailable"))
|
representation = captures_representation(self.microscope.camera.images)
|
||||||
|
|
||||||
representation = captures_representation(self.microscope.camera.images, include_unavailable=include_unavailable)
|
|
||||||
|
|
||||||
return jsonify(representation)
|
return jsonify(representation)
|
||||||
|
|
||||||
|
|
@ -132,11 +130,9 @@ class CaptureAPI(MicroscopeView):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
all_captures = captures_representation(self.microscope.camera.images, include_unavailable=True)
|
try:
|
||||||
|
representation = captures_representation(self.microscope.camera.images)[capture_id]
|
||||||
if capture_id in all_captures:
|
except KeyError:
|
||||||
representation = all_captures[capture_id]
|
|
||||||
else:
|
|
||||||
return abort(404) # 404 Not Found
|
return abort(404) # 404 Not Found
|
||||||
|
|
||||||
return jsonify(representation)
|
return jsonify(representation)
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@ class TaskAPI(MethodView):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
task = tasks.tasks()[task_id]
|
task = tasks_representation()[task_id]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return abort(404) # 404 Not Found
|
return abort(404) # 404 Not Found
|
||||||
|
|
||||||
|
|
@ -140,7 +140,7 @@ class TaskAPI(MethodView):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
task = tasks.tasks()[task_id]
|
task = tasks_representation()[task_id]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return abort(404) # 404 Not Found
|
return abort(404) # 404 Not Found
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ class AutofocusAPI(MicroscopeViewPlugin):
|
||||||
else:
|
else:
|
||||||
abort(503, 'No stage connected. Unable to autofocus.')
|
abort(503, 'No stage connected. Unable to autofocus.')
|
||||||
|
|
||||||
|
|
||||||
class FastAutofocusAPI(MicroscopeViewPlugin):
|
class FastAutofocusAPI(MicroscopeViewPlugin):
|
||||||
def post(self):
|
def post(self):
|
||||||
payload = JsonResponse(request)
|
payload = JsonResponse(request)
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ from openflexure_microscope.common.tasks import (
|
||||||
remove_task,
|
remove_task,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# DEPRECATED
|
||||||
class TaskOrchestrator:
|
class TaskOrchestrator:
|
||||||
"""
|
"""
|
||||||
DEPRECATED: Class responsible for spawning threaded tasks, and storing their returns.
|
DEPRECATED: Class responsible for spawning threaded tasks, and storing their returns.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue