Went on a PEP-8 rampage
This commit is contained in:
parent
f99ad30fb6
commit
0948c9308a
36 changed files with 186 additions and 218 deletions
|
|
@ -1,31 +1,16 @@
|
|||
#!/usr/bin/env python
|
||||
"""
|
||||
TODO: Implement API route to cleanly shut down server
|
||||
TODO: Implement plugin API routes somehow
|
||||
"""
|
||||
|
||||
import numpy as np
|
||||
from importlib import import_module
|
||||
import time
|
||||
import datetime
|
||||
import os
|
||||
|
||||
from flask import (
|
||||
Flask, render_template, Response, url_for,
|
||||
redirect, request, jsonify, send_file, abort,
|
||||
make_response)
|
||||
|
||||
from flask.views import MethodView
|
||||
from werkzeug.exceptions import default_exceptions
|
||||
from serial import SerialException
|
||||
Flask, render_template)
|
||||
|
||||
from flask_cors import CORS
|
||||
|
||||
from openflexure_microscope.api.utilities import list_routes
|
||||
from openflexure_microscope.api.exceptions import JSONExceptionHandler
|
||||
|
||||
from openflexure_microscope import Microscope
|
||||
from openflexure_microscope.exceptions import LockError
|
||||
from openflexure_microscope.camera.pi import StreamingCamera
|
||||
from openflexure_microscope.stage.openflexure import Stage
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ from flask import jsonify
|
|||
from werkzeug.exceptions import default_exceptions
|
||||
from werkzeug.exceptions import HTTPException
|
||||
|
||||
|
||||
class JSONExceptionHandler(object):
|
||||
|
||||
def __init__(self, app=None):
|
||||
|
|
@ -24,7 +25,6 @@ class JSONExceptionHandler(object):
|
|||
}
|
||||
return jsonify(response)
|
||||
|
||||
|
||||
def init_app(self, app):
|
||||
self.app = app
|
||||
self.register(HTTPException)
|
||||
|
|
@ -32,4 +32,4 @@ class JSONExceptionHandler(object):
|
|||
self.register(code)
|
||||
|
||||
def register(self, exception_or_code, handler=None):
|
||||
self.app.errorhandler(exception_or_code)(handler or self.std_handler)
|
||||
self.app.errorhandler(exception_or_code)(handler or self.std_handler)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import pprint
|
||||
import logging
|
||||
import copy
|
||||
from werkzeug.exceptions import BadRequest
|
||||
|
||||
|
||||
class JsonPayload:
|
||||
def __init__(self, request):
|
||||
"""
|
||||
|
|
@ -60,10 +60,9 @@ def gen(camera):
|
|||
|
||||
def get_bool(get_arg):
|
||||
"""Convert GET request argument string to a Python bool"""
|
||||
if (
|
||||
get_arg == 'true' or
|
||||
get_arg == 'True' or
|
||||
get_arg == '1'):
|
||||
if (get_arg == 'true' or
|
||||
get_arg == 'True' or
|
||||
get_arg == '1'):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -197,4 +197,4 @@ def construct_blueprint(microscope_obj):
|
|||
view_func=ConfigAPI.as_view('config', microscope=microscope_obj)
|
||||
)
|
||||
|
||||
return(blueprint)
|
||||
return blueprint
|
||||
|
|
|
|||
|
|
@ -2,9 +2,7 @@ from openflexure_microscope.api.utilities import gen, get_bool, JsonPayload
|
|||
from openflexure_microscope.api.v1.views import MicroscopeView
|
||||
from openflexure_microscope.utilities import filter_dict
|
||||
|
||||
from flask import Response, Blueprint, jsonify, request, abort, url_for, redirect, send_file
|
||||
|
||||
import logging
|
||||
from flask import Response, jsonify, request, abort, url_for, redirect, send_file
|
||||
|
||||
|
||||
class ListAPI(MicroscopeView):
|
||||
|
|
@ -368,7 +366,7 @@ 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, as_attachment=as_attachment), 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
|
||||
|
|
@ -377,6 +375,7 @@ class MetadataAPI(MicroscopeView):
|
|||
data,
|
||||
mimetype="text/yaml")
|
||||
|
||||
|
||||
class TagsAPI(MicroscopeView):
|
||||
def get(self, capture_id):
|
||||
"""
|
||||
|
|
@ -402,7 +401,7 @@ class TagsAPI(MicroscopeView):
|
|||
if not capture_obj or not capture_obj.state['available']:
|
||||
return abort(404) # 404 Not Found
|
||||
|
||||
metadata_tags = filter_dict(capture_obj.state, ('metadata', 'tags'))
|
||||
metadata_tags = filter_dict(capture_obj.state, ['metadata', 'tags'])
|
||||
|
||||
return jsonify(metadata_tags)
|
||||
|
||||
|
|
@ -440,7 +439,7 @@ class TagsAPI(MicroscopeView):
|
|||
for tag in data_dict:
|
||||
capture_obj.put_tag(str(tag))
|
||||
|
||||
metadata_tags = filter_dict(capture_obj.state, ('metadata', 'tags'))
|
||||
metadata_tags = filter_dict(capture_obj.state, ['metadata', 'tags'])
|
||||
|
||||
return jsonify(metadata_tags)
|
||||
|
||||
|
|
@ -477,6 +476,6 @@ class TagsAPI(MicroscopeView):
|
|||
for tag in data_dict:
|
||||
capture_obj.delete_tag(str(tag))
|
||||
|
||||
metadata_tags = filter_dict(capture_obj.state, ('metadata', 'tags'))
|
||||
metadata_tags = filter_dict(capture_obj.state, ['metadata', 'tags'])
|
||||
|
||||
return jsonify(metadata_tags)
|
||||
return jsonify(metadata_tags)
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
from openflexure_microscope.api.v1.views import MicroscopeView
|
||||
from openflexure_microscope.api.utilities import JsonPayload
|
||||
|
||||
from flask import Response, Blueprint, jsonify, request, abort, url_for, redirect, send_file
|
||||
|
||||
import logging
|
||||
from flask import jsonify, request
|
||||
|
||||
|
||||
class ZoomAPI(MicroscopeView):
|
||||
|
|
@ -102,4 +100,4 @@ class OverlayAPI(MicroscopeView):
|
|||
self.microscope.camera.camera.annotate_text = text
|
||||
self.microscope.camera.camera.annotate_text_size = size
|
||||
|
||||
return jsonify({'text': text, 'size': size})
|
||||
return jsonify({'text': text, 'size': size})
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
from openflexure_microscope.api.v1.views import MicroscopeView
|
||||
|
||||
from flask import Response, Blueprint, jsonify, request, abort, url_for, redirect, send_file
|
||||
|
||||
import logging
|
||||
from flask import jsonify
|
||||
|
||||
|
||||
class GPUPreviewAPI(MicroscopeView):
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
from openflexure_microscope.api.v1.views import MicroscopeViewPlugin
|
||||
|
||||
from flask import Response, Blueprint, jsonify
|
||||
from flask import Blueprint
|
||||
|
||||
import logging, warnings
|
||||
import logging
|
||||
import warnings
|
||||
|
||||
|
||||
def construct_blueprint(microscope_obj, plugin_paths=[], include_default=True):
|
||||
def construct_blueprint(microscope_obj):
|
||||
|
||||
blueprint = Blueprint('plugin_blueprint', __name__)
|
||||
|
||||
|
|
@ -56,4 +57,4 @@ def construct_blueprint(microscope_obj, plugin_paths=[], include_default=True):
|
|||
"No valid 'api_views' dictionary found in {}".format(plugin_obj)
|
||||
)
|
||||
|
||||
return(blueprint)
|
||||
return blueprint
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from openflexure_microscope.api.utilities import gen, JsonPayload
|
|||
from openflexure_microscope.api.v1.views import MicroscopeView
|
||||
from openflexure_microscope.utilities import axes_to_array, filter_dict
|
||||
|
||||
from flask import Response, Blueprint, jsonify, request
|
||||
from flask import Blueprint, jsonify, request
|
||||
|
||||
import logging
|
||||
|
||||
|
|
@ -42,7 +42,7 @@ class PositionAPI(MicroscopeView):
|
|||
}
|
||||
|
||||
"""
|
||||
out = filter_dict(self.microscope.state, ('stage', 'position'))
|
||||
out = filter_dict(self.microscope.state, ['stage', 'position'])
|
||||
return jsonify(out)
|
||||
|
||||
def post(self):
|
||||
|
|
@ -85,7 +85,7 @@ class PositionAPI(MicroscopeView):
|
|||
with self.microscope.stage.lock:
|
||||
self.microscope.stage.move_rel(position)
|
||||
|
||||
out = filter_dict(self.microscope.state, ('stage', 'position'))
|
||||
out = filter_dict(self.microscope.state, ['stage', 'position'])
|
||||
|
||||
return jsonify(out)
|
||||
|
||||
|
|
@ -99,4 +99,4 @@ def construct_blueprint(microscope_obj):
|
|||
view_func=PositionAPI.as_view('position', microscope=microscope_obj)
|
||||
)
|
||||
|
||||
return(blueprint)
|
||||
return blueprint
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
from openflexure_microscope.api.v1.views import MicroscopeView
|
||||
from flask import jsonify, abort, Blueprint
|
||||
|
||||
|
||||
class TaskListAPI(MicroscopeView):
|
||||
|
||||
def get(self):
|
||||
|
|
@ -65,6 +66,7 @@ class TaskListAPI(MicroscopeView):
|
|||
|
||||
return jsonify(data)
|
||||
|
||||
|
||||
class TaskAPI(MicroscopeView):
|
||||
|
||||
def get(self, task_id):
|
||||
|
|
@ -135,6 +137,7 @@ class TaskAPI(MicroscopeView):
|
|||
|
||||
return jsonify(data)
|
||||
|
||||
|
||||
def construct_blueprint(microscope_obj):
|
||||
|
||||
blueprint = Blueprint('task_blueprint', __name__)
|
||||
|
|
@ -149,4 +152,4 @@ def construct_blueprint(microscope_obj):
|
|||
view_func=TaskAPI.as_view('task', microscope=microscope_obj)
|
||||
)
|
||||
|
||||
return(blueprint)
|
||||
return blueprint
|
||||
|
|
|
|||
|
|
@ -23,4 +23,4 @@ class MicroscopeViewPlugin(MicroscopeView):
|
|||
|
||||
self.plugin = plugin
|
||||
|
||||
MicroscopeView.__init__(self, microscope=microscope, **kwargs)
|
||||
MicroscopeView.__init__(self, microscope=microscope, **kwargs)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue