Code cleanup
This commit is contained in:
parent
2bfb988460
commit
994e83dbeb
46 changed files with 261 additions and 318 deletions
|
|
@ -53,7 +53,6 @@ _actions = {
|
|||
|
||||
|
||||
def enabled_root_actions():
|
||||
global _actions
|
||||
return {k: v for k, v in _actions.items() if v["conditions"]}
|
||||
|
||||
|
||||
|
|
@ -65,8 +64,6 @@ class ActionsView(View):
|
|||
This list does not include any actions added by LabThings extensions, only
|
||||
those part of the default OpenFlexure Microscope API.
|
||||
"""
|
||||
global _actions
|
||||
|
||||
actions = {}
|
||||
for name, action in enabled_root_actions().items():
|
||||
d = {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,11 @@
|
|||
import io
|
||||
import logging
|
||||
|
||||
from flask import abort, redirect, request, send_file, url_for
|
||||
from flask import abort, send_file
|
||||
from labthings import fields, find_component
|
||||
from labthings.views import ActionView, View
|
||||
from labthings.views import ActionView
|
||||
|
||||
from openflexure_microscope.api.utilities import JsonResponse, get_bool
|
||||
from openflexure_microscope.api.v2.views.captures import CaptureSchema
|
||||
from openflexure_microscope.utilities import filter_dict
|
||||
|
||||
|
||||
class CaptureAPI(ActionView):
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
import logging
|
||||
|
||||
from flask import Blueprint, request
|
||||
from labthings import fields, find_component
|
||||
from labthings.views import ActionView, View
|
||||
from labthings.views import ActionView
|
||||
|
||||
from openflexure_microscope.api.utilities import JsonResponse
|
||||
from openflexure_microscope.utilities import axes_to_array, filter_dict
|
||||
from openflexure_microscope.utilities import axes_to_array
|
||||
|
||||
|
||||
class MoveStageAPI(ActionView):
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
import os
|
||||
import subprocess
|
||||
from sys import platform
|
||||
|
||||
from labthings.views import ActionView, View
|
||||
from labthings.views import ActionView
|
||||
|
||||
|
||||
def is_raspberrypi(raise_on_errors=False):
|
||||
def is_raspberrypi():
|
||||
"""
|
||||
Checks if Raspberry Pi.
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -45,9 +45,8 @@ class CaptureSchema(Schema):
|
|||
|
||||
links = fields.Dict()
|
||||
|
||||
# TODO: Automate this somewhat
|
||||
@pre_dump
|
||||
def generate_links(self, data, **kwargs):
|
||||
def generate_links(self, data, **_):
|
||||
data.links = {
|
||||
"self": {
|
||||
"href": url_for(CaptureView.endpoint, id=data.id, _external=True),
|
||||
|
|
@ -97,24 +96,24 @@ class CaptureView(View):
|
|||
tags = ["captures"]
|
||||
|
||||
@marshal_with(CaptureSchema())
|
||||
def get(self, id):
|
||||
def get(self, id_):
|
||||
"""
|
||||
Description of a single image capture
|
||||
"""
|
||||
microscope = find_component("org.openflexure.microscope")
|
||||
capture_obj = microscope.captures.images.get(id)
|
||||
capture_obj = microscope.captures.images.get(id_)
|
||||
|
||||
if not capture_obj:
|
||||
return abort(404) # 404 Not Found
|
||||
|
||||
return capture_obj
|
||||
|
||||
def delete(self, id):
|
||||
def delete(self, id_):
|
||||
"""
|
||||
Delete a single image capture
|
||||
"""
|
||||
microscope = find_component("org.openflexure.microscope")
|
||||
capture_obj = microscope.captures.images.get(id)
|
||||
capture_obj = microscope.captures.images.get(id_)
|
||||
|
||||
if not capture_obj:
|
||||
return abort(404) # 404 Not Found
|
||||
|
|
@ -122,7 +121,7 @@ class CaptureView(View):
|
|||
# Delete the capture file
|
||||
capture_obj.delete()
|
||||
# Delete from capture list
|
||||
del microscope.captures.images[id]
|
||||
del microscope.captures.images[id_]
|
||||
|
||||
return "", 204
|
||||
|
||||
|
|
@ -131,12 +130,12 @@ class CaptureDownload(View):
|
|||
tags = ["captures"]
|
||||
responses = {200: {"content_type": "image/jpeg"}}
|
||||
|
||||
def get(self, id, filename):
|
||||
def get(self, id_, filename):
|
||||
"""
|
||||
Image data for a single image capture
|
||||
"""
|
||||
microscope = find_component("org.openflexure.microscope")
|
||||
capture_obj = microscope.captures.images.get(id)
|
||||
capture_obj = microscope.captures.images.get(id_)
|
||||
|
||||
if not capture_obj:
|
||||
return abort(404) # 404 Not Found
|
||||
|
|
@ -148,7 +147,7 @@ class CaptureDownload(View):
|
|||
return redirect(
|
||||
url_for(
|
||||
"DownloadAPI",
|
||||
id=id,
|
||||
id=id_,
|
||||
filename=capture_obj.filename,
|
||||
thumbnail=thumbnail,
|
||||
),
|
||||
|
|
@ -167,24 +166,24 @@ class CaptureDownload(View):
|
|||
class CaptureTags(View):
|
||||
tags = ["captures"]
|
||||
|
||||
def get(self, id):
|
||||
def get(self, id_):
|
||||
"""
|
||||
Get tags associated with a single image capture
|
||||
"""
|
||||
microscope = find_component("org.openflexure.microscope")
|
||||
capture_obj = microscope.captures.images.get(id)
|
||||
capture_obj = microscope.captures.images.get(id_)
|
||||
|
||||
if not capture_obj:
|
||||
return abort(404) # 404 Not Found
|
||||
|
||||
return capture_obj.tags
|
||||
|
||||
def put(self, id):
|
||||
def put(self, id_):
|
||||
"""
|
||||
Add tags to a single image capture
|
||||
"""
|
||||
microscope = find_component("org.openflexure.microscope")
|
||||
capture_obj = microscope.captures.images.get(id)
|
||||
capture_obj = microscope.captures.images.get(id_)
|
||||
|
||||
if not capture_obj:
|
||||
return abort(404) # 404 Not Found
|
||||
|
|
@ -199,12 +198,12 @@ class CaptureTags(View):
|
|||
|
||||
return capture_obj.tags
|
||||
|
||||
def delete(self, id):
|
||||
def delete(self, id_):
|
||||
"""
|
||||
Delete tags from a single image capture
|
||||
"""
|
||||
microscope = find_component("org.openflexure.microscope")
|
||||
capture_obj = microscope.captures.images.get(id)
|
||||
capture_obj = microscope.captures.images.get(id_)
|
||||
|
||||
if not capture_obj:
|
||||
return abort(404) # 404 Not Found
|
||||
|
|
@ -223,24 +222,24 @@ class CaptureTags(View):
|
|||
class CaptureAnnotations(View):
|
||||
tags = ["captures"]
|
||||
|
||||
def get(self, id):
|
||||
def get(self, id_):
|
||||
"""
|
||||
Get annotations associated with a single image capture
|
||||
"""
|
||||
microscope = find_component("org.openflexure.microscope")
|
||||
capture_obj = microscope.captures.images.get(id)
|
||||
capture_obj = microscope.captures.images.get(id_)
|
||||
|
||||
if not capture_obj:
|
||||
return abort(404) # 404 Not Found
|
||||
|
||||
return capture_obj.annotations
|
||||
|
||||
def put(self, id):
|
||||
def put(self, id_):
|
||||
"""
|
||||
Update metadata for a single image capture
|
||||
"""
|
||||
microscope = find_component("org.openflexure.microscope")
|
||||
capture_obj = microscope.captures.images.get(id)
|
||||
capture_obj = microscope.captures.images.get(id_)
|
||||
|
||||
if not capture_obj:
|
||||
return abort(404) # 404 Not Found
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
import logging
|
||||
|
||||
from labthings import fields, find_component, schema
|
||||
from labthings import fields, find_component
|
||||
from labthings.views import PropertyView
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
from flask import Response
|
||||
from labthings import find_component
|
||||
from labthings.utilities import create_from_path, get_by_path, set_by_path
|
||||
from labthings.views import PropertyView, View
|
||||
from labthings.views import PropertyView
|
||||
|
||||
from openflexure_microscope.api.utilities import JsonResponse, gen
|
||||
from openflexure_microscope.api.utilities import gen
|
||||
|
||||
|
||||
class MjpegStream(PropertyView):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue