Commit 0948c930 authored by Joel Collins's avatar Joel Collins
Browse files

Went on a PEP-8 rampage

parent f99ad30f
Loading
Loading
Loading
Loading
+1 −16
Original line number Diff line number Diff line
#!/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

+1 −1
Original line number Diff line number Diff line
@@ -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)
+2 −3
Original line number Diff line number Diff line
import pprint
import logging
import copy
from werkzeug.exceptions import BadRequest


class JsonPayload:
    def __init__(self, request):
        """
@@ -60,8 +60,7 @@ def gen(camera):

def get_bool(get_arg):
    """Convert GET request argument string to a Python bool"""
    if (
        get_arg == 'true' or
    if (get_arg == 'true' or
            get_arg == 'True' or
            get_arg == '1'):
        return True
+1 −1
Original line number Diff line number Diff line
@@ -197,4 +197,4 @@ def construct_blueprint(microscope_obj):
        view_func=ConfigAPI.as_view('config', microscope=microscope_obj)
    )

    return(blueprint)
    return blueprint
+6 −7
Original line number Diff line number Diff line
@@ -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)
Loading