Blackened
This commit is contained in:
parent
0907d013cd
commit
76af0891e9
14 changed files with 95 additions and 63 deletions
|
|
@ -132,11 +132,11 @@ class ListAPI(MicroscopeView):
|
|||
|
||||
# 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,
|
||||
}
|
||||
"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
|
||||
|
|
|
|||
|
|
@ -8,38 +8,38 @@ _actions = {
|
|||
"rule": "/camera/capture/",
|
||||
"view_class": camera.CaptureAPI,
|
||||
"description": "Take a single still capture",
|
||||
"conditions": True
|
||||
"conditions": True,
|
||||
},
|
||||
"preview_start": {
|
||||
"rule": "/camera/preview/start",
|
||||
"view_class": camera.GPUPreviewStartAPI,
|
||||
"description": "Start the on-board GPU preview",
|
||||
"conditions": True
|
||||
"conditions": True,
|
||||
},
|
||||
"preview_stop": {
|
||||
"rule": "/camera/preview/stop",
|
||||
"view_class": camera.GPUPreviewStopAPI,
|
||||
"description": "Stop the on-board GPU preview",
|
||||
"conditions": True
|
||||
"conditions": True,
|
||||
},
|
||||
"move": {
|
||||
"rule": "/stage/move/",
|
||||
"view_class": stage.MoveStageAPI,
|
||||
"description": "Move the microscope stage",
|
||||
"conditions": True
|
||||
"conditions": True,
|
||||
},
|
||||
"shutdown": {
|
||||
"rule": "/system/shutdown/",
|
||||
"view_class": system.ShutdownAPI,
|
||||
"description": "Shutdown the device",
|
||||
"conditions": (platform == "linux")
|
||||
"conditions": (platform == "linux"),
|
||||
},
|
||||
"reboot": {
|
||||
"rule": "/system/reboot/",
|
||||
"view_class": system.RebootAPI,
|
||||
"description": "Reboot the device",
|
||||
"conditions": (platform == "linux")
|
||||
}
|
||||
"conditions": (platform == "linux"),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -57,7 +57,7 @@ def actions_representation():
|
|||
"links": {"self": url_for(f".{name}")},
|
||||
"description": action["description"],
|
||||
"rule": action["rule"],
|
||||
"view_class": str(action["view_class"])
|
||||
"view_class": str(action["view_class"]),
|
||||
}
|
||||
|
||||
actions[name] = d
|
||||
|
|
|
|||
|
|
@ -84,11 +84,11 @@ class CaptureAPI(MicroscopeView):
|
|||
|
||||
# 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,
|
||||
}
|
||||
"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
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class ShutdownAPI(MicroscopeView):
|
|||
.. :quickref: Actions; Shutdown
|
||||
|
||||
"""
|
||||
subprocess.Popen(['shutdown', '-h', 'now'])
|
||||
subprocess.Popen(["shutdown", "-h", "now"])
|
||||
|
||||
return "{}", 201
|
||||
|
||||
|
|
@ -24,6 +24,6 @@ class RebootAPI(MicroscopeView):
|
|||
.. :quickref: Actions; Shutdown
|
||||
|
||||
"""
|
||||
subprocess.Popen(['sudo', 'shutdown', '-r', 'now'])
|
||||
subprocess.Popen(["sudo", "shutdown", "-r", "now"])
|
||||
|
||||
return "{}", 201
|
||||
|
|
|
|||
|
|
@ -20,14 +20,22 @@ def captures_representation(capture_list: list, include_unavailable: bool = Fals
|
|||
if include_unavailable:
|
||||
captures = {image.id: image.state for image in capture_list}
|
||||
else:
|
||||
captures = {image.id: image.state for image in capture_list if image.state["available"]}
|
||||
captures = {
|
||||
image.id: image.state for image in capture_list if image.state["available"]
|
||||
}
|
||||
|
||||
for capture_key, capture_repr in captures.items():
|
||||
# Add API routes to returned representations
|
||||
extra_state = {
|
||||
"links": {
|
||||
"self": "{}".format(url_for(".capture", capture_id=capture_key)),
|
||||
"download": "{}".format(url_for(".capture_download", capture_id=capture_key, filename=capture_repr["filename"])),
|
||||
"download": "{}".format(
|
||||
url_for(
|
||||
".capture_download",
|
||||
capture_id=capture_key,
|
||||
filename=capture_repr["filename"],
|
||||
)
|
||||
),
|
||||
"tags": "{}".format(url_for(".capture_tags", capture_id=capture_key)),
|
||||
}
|
||||
}
|
||||
|
|
@ -131,7 +139,9 @@ class CaptureAPI(MicroscopeView):
|
|||
"""
|
||||
|
||||
try:
|
||||
representation = captures_representation(self.microscope.camera.images)[capture_id]
|
||||
representation = captures_representation(self.microscope.camera.images)[
|
||||
capture_id
|
||||
]
|
||||
except KeyError:
|
||||
return abort(404) # 404 Not Found
|
||||
|
||||
|
|
@ -379,9 +389,7 @@ def construct_blueprint(microscope_obj):
|
|||
# Capture routes
|
||||
blueprint.add_url_rule(
|
||||
"/<capture_id>/download/<filename>",
|
||||
view_func=DownloadAPI.as_view(
|
||||
"capture_download", microscope=microscope_obj
|
||||
),
|
||||
view_func=DownloadAPI.as_view("capture_download", microscope=microscope_obj),
|
||||
)
|
||||
|
||||
blueprint.add_url_rule(
|
||||
|
|
@ -397,7 +405,6 @@ def construct_blueprint(microscope_obj):
|
|||
)
|
||||
|
||||
blueprint.add_url_rule(
|
||||
"/",
|
||||
view_func=ListAPI.as_view("capture_list", microscope=microscope_obj),
|
||||
"/", view_func=ListAPI.as_view("capture_list", microscope=microscope_obj)
|
||||
)
|
||||
return blueprint
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ def plugins_representation(plugin_loader_object: PluginLoader):
|
|||
"name": plugin["name"],
|
||||
"plugin": str(plugin["plugin"]),
|
||||
"routes": plugin["routes"],
|
||||
"form": plugin["form"]
|
||||
"form": plugin["form"],
|
||||
}
|
||||
plugins.append(d)
|
||||
|
||||
|
|
@ -55,8 +55,7 @@ def construct_blueprint(microscope_obj):
|
|||
|
||||
# Create a base route to return plugin API forms, if any exist
|
||||
blueprint.add_url_rule(
|
||||
"/",
|
||||
view_func=PluginFormAPI.as_view("plugins", microscope=microscope_obj),
|
||||
"/", view_func=PluginFormAPI.as_view("plugins", microscope=microscope_obj)
|
||||
)
|
||||
|
||||
all_routes = []
|
||||
|
|
|
|||
|
|
@ -16,9 +16,7 @@ def tasks_representation():
|
|||
for task_key, task_repr in tasks_dict.items():
|
||||
# Add API routes to returned representations
|
||||
extra_state = {
|
||||
"links": {
|
||||
"self": "{}".format(url_for(".task", task_id=task_key)),
|
||||
}
|
||||
"links": {"self": "{}".format(url_for(".task", task_id=task_key))}
|
||||
}
|
||||
|
||||
tasks_dict[task_key].update(extra_state)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue