Improved flake8 results
This commit is contained in:
parent
fb606b189d
commit
3b9ef670fe
24 changed files with 256 additions and 126 deletions
|
|
@ -1 +1,3 @@
|
|||
__all__ = ['utilities']
|
||||
|
||||
from . import utilities
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from flask import (
|
||||
Flask, render_template, jsonify, send_file)
|
||||
Flask, jsonify, send_file)
|
||||
|
||||
from flask.logging import default_handler
|
||||
from serial import SerialException
|
||||
from datetime import datetime
|
||||
|
||||
|
|
@ -21,9 +20,12 @@ from openflexure_microscope.camera.capture import build_captures_from_exif
|
|||
|
||||
from openflexure_microscope.config import USER_CONFIG_DIR
|
||||
|
||||
from openflexure_microscope.api.v1 import blueprints
|
||||
|
||||
import atexit
|
||||
import logging
|
||||
import sys, os
|
||||
import sys
|
||||
import os
|
||||
|
||||
# Handle logging
|
||||
is_gunicorn = "gunicorn" in os.environ.get("SERVER_SOFTWARE", "")
|
||||
|
|
@ -63,6 +65,7 @@ api_microscope = Microscope(None, None)
|
|||
# TODO: Offload to a thread?
|
||||
stored_image_list = build_captures_from_exif()
|
||||
|
||||
|
||||
# Generate API URI based on version from filename
|
||||
def uri(suffix, api_version, base=None):
|
||||
if not base:
|
||||
|
|
@ -91,7 +94,7 @@ def attach_microscope():
|
|||
|
||||
logging.debug("Creating camera object...")
|
||||
api_camera = StreamingCamera(config=api_microscope.rc.read())
|
||||
|
||||
|
||||
logging.debug("Creating stage object...")
|
||||
try:
|
||||
api_stage = SangaStage()
|
||||
|
|
@ -113,10 +116,9 @@ def attach_microscope():
|
|||
logging.debug("Microscope successfully attached!")
|
||||
|
||||
|
||||
##### WEBAPP ROUTES ######
|
||||
# WEBAPP ROUTES
|
||||
|
||||
##### API ROUTES ######
|
||||
from openflexure_microscope.api.v1 import blueprints
|
||||
# API ROUTES
|
||||
|
||||
# Base routes
|
||||
base_blueprint = blueprints.base.construct_blueprint(api_microscope)
|
||||
|
|
@ -138,6 +140,7 @@ app.register_blueprint(plugin_blueprint, url_prefix=uri('/plugin', 'v1'))
|
|||
task_blueprint = blueprints.task.construct_blueprint(api_microscope)
|
||||
app.register_blueprint(task_blueprint, url_prefix=uri('/task', 'v1'))
|
||||
|
||||
|
||||
@app.route('/routes')
|
||||
def routes():
|
||||
"""
|
||||
|
|
@ -145,13 +148,19 @@ def routes():
|
|||
"""
|
||||
return jsonify(list_routes(app))
|
||||
|
||||
|
||||
@app.route('/log')
|
||||
def err_log():
|
||||
"""
|
||||
Most recent 1mb of log output
|
||||
"""
|
||||
timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
|
||||
return send_file(DEFAULT_LOGFILE, as_attachment=True, attachment_filename='openflexure_microscope_{}.log'.format(timestamp))
|
||||
return send_file(
|
||||
DEFAULT_LOGFILE,
|
||||
as_attachment=True,
|
||||
attachment_filename='openflexure_microscope_{}.log'.format(timestamp)
|
||||
)
|
||||
|
||||
|
||||
# Automatically clean up microscope at exit
|
||||
def cleanup():
|
||||
|
|
@ -166,6 +175,7 @@ def cleanup():
|
|||
api_microscope.close()
|
||||
logging.debug("App teardown complete.")
|
||||
|
||||
|
||||
atexit.register(cleanup)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import pprint
|
||||
import logging
|
||||
from werkzeug.exceptions import BadRequest
|
||||
from flask import url_for
|
||||
|
||||
|
||||
class JsonPayload:
|
||||
def __init__(self, request):
|
||||
"""
|
||||
|
|
@ -32,7 +32,8 @@ class JsonPayload:
|
|||
Args:
|
||||
key (str): JSON key to look for
|
||||
default: Value to return if no matching key-value pair is found.
|
||||
convert: Converter function. By passing a type, the value will be converted to that type. **Use with caution!**
|
||||
convert: Converter function. By passing a type, the value will be converted to that type.
|
||||
**Use with caution!**
|
||||
"""
|
||||
# If no JSON payload exists, make an empty dictionary
|
||||
if not self.json:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from openflexure_microscope.api.utilities import gen, get_bool, JsonPayload
|
||||
from openflexure_microscope.api.utilities import get_bool, JsonPayload
|
||||
from openflexure_microscope.api.v1.views import MicroscopeView
|
||||
from openflexure_microscope.utilities import filter_dict
|
||||
|
||||
|
|
@ -201,7 +201,10 @@ class CaptureAPI(MicroscopeView):
|
|||
|
||||
# If available, also add download link
|
||||
if capture_metadata['available']:
|
||||
uri_dict['uri']['download'] = '{}download/{}'.format(url_for('.capture', capture_id=capture_obj.id), capture_obj.filename)
|
||||
uri_dict['uri']['download'] = '{}download/{}'.format(
|
||||
url_for('.capture', capture_id=capture_obj.id),
|
||||
capture_obj.filename
|
||||
)
|
||||
|
||||
capture_metadata.update(uri_dict)
|
||||
|
||||
|
|
@ -297,7 +300,12 @@ class DownloadRedirectAPI(MicroscopeView):
|
|||
|
||||
thumbnail = get_bool(request.args.get('thumbnail'))
|
||||
|
||||
return redirect(url_for('.capture_download', capture_id=capture_id, filename=capture_obj.filename, thumbnail=thumbnail), code=307)
|
||||
return redirect(url_for(
|
||||
'.capture_download',
|
||||
capture_id=capture_id,
|
||||
filename=capture_obj.filename,
|
||||
thumbnail=thumbnail
|
||||
), code=307)
|
||||
|
||||
|
||||
class DownloadAPI(MicroscopeView):
|
||||
|
|
@ -312,7 +320,12 @@ class DownloadAPI(MicroscopeView):
|
|||
|
||||
# If no filename is specified, redirect to the capture's currently set filename
|
||||
if not filename:
|
||||
return redirect(url_for('capture_download', capture_id=capture_id, filename=capture_obj.filename, thumbnail=thumbnail), code=307)
|
||||
return redirect(url_for(
|
||||
'capture_download',
|
||||
capture_id=capture_id,
|
||||
filename=capture_obj.filename,
|
||||
thumbnail=thumbnail
|
||||
), code=307)
|
||||
|
||||
# Download the image data using the requested filename
|
||||
if thumbnail:
|
||||
|
|
@ -360,7 +373,11 @@ class MetadataRedirectAPI(MicroscopeView):
|
|||
if not capture_obj or not capture_obj.state['available']:
|
||||
return abort(404) # 404 Not Found
|
||||
|
||||
return redirect(url_for('.metadata_download', capture_id=capture_id, filename=capture_obj.metadataname), code=307)
|
||||
return redirect(url_for(
|
||||
'.metadata_download',
|
||||
capture_id=capture_id,
|
||||
filename=capture_obj.metadataname
|
||||
), code=307)
|
||||
|
||||
|
||||
class MetadataAPI(MicroscopeView):
|
||||
|
|
@ -373,7 +390,11 @@ class MetadataAPI(MicroscopeView):
|
|||
|
||||
# If no filename is specified, redirect to the capture's currently set filename
|
||||
if not filename:
|
||||
return redirect(url_for('capture_download', capture_id=capture_id, filename=capture_obj.metadataname), code=307)
|
||||
return redirect(url_for(
|
||||
'capture_download',
|
||||
capture_id=capture_id,
|
||||
filename=capture_obj.metadataname
|
||||
), code=307)
|
||||
|
||||
# Download the metadata using the requested filename
|
||||
data = capture_obj.yaml
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ class ZoomAPI(MicroscopeView):
|
|||
Accept: application/json
|
||||
|
||||
{
|
||||
"zoom_value": 2.5,
|
||||
"zoom_value": 2.5,
|
||||
}
|
||||
|
||||
:>header Accept: application/json
|
||||
|
|
@ -83,8 +83,8 @@ class OverlayAPI(MicroscopeView):
|
|||
Accept: application/json
|
||||
|
||||
{
|
||||
"text": "2019/01/15 14:48",
|
||||
"size": 50
|
||||
"text": "2019/01/15 14:48",
|
||||
"size": 50
|
||||
}
|
||||
|
||||
:>header Accept: application/json
|
||||
|
|
@ -92,7 +92,7 @@ class OverlayAPI(MicroscopeView):
|
|||
:<header Content-Type: application/json
|
||||
:status 200: preview started/stopped
|
||||
"""
|
||||
|
||||
|
||||
payload = JsonPayload(request)
|
||||
text = payload.param('text', default="", convert=str)
|
||||
size = payload.param('size', default=50, convert=int)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ from openflexure_microscope.api.v1.views import MicroscopeView
|
|||
from flask import jsonify, request
|
||||
import logging
|
||||
|
||||
|
||||
class GPUPreviewAPI(MicroscopeView):
|
||||
|
||||
def post(self, operation):
|
||||
|
|
@ -45,8 +46,8 @@ class GPUPreviewAPI(MicroscopeView):
|
|||
fullscreen = True
|
||||
window = None
|
||||
else:
|
||||
fullscreen = False
|
||||
window = [int(w) for w in window]
|
||||
fullscreen = False
|
||||
window = [int(w) for w in window]
|
||||
|
||||
self.microscope.camera.start_preview(fullscreen=fullscreen, window=window)
|
||||
elif operation == "stop":
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from openflexure_microscope.api.utilities import gen, JsonPayload
|
||||
from openflexure_microscope.api.utilities import JsonPayload
|
||||
from openflexure_microscope.api.v1.views import MicroscopeView
|
||||
from openflexure_microscope.utilities import axes_to_array, filter_dict
|
||||
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ class TaskAPI(MicroscopeView):
|
|||
"""
|
||||
|
||||
success = self.microscope.task.delete(task_id)
|
||||
|
||||
|
||||
if success:
|
||||
data = {
|
||||
'status': 'success',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue