Commit 259ec415 authored by Joel Collins's avatar Joel Collins
Browse files

Minor restructure

parent 3b28f8c4
Loading
Loading
Loading
Loading
+12 −15
Original line number Diff line number Diff line
#!/usr/bin/env python
"""
TODO: Add proper docstrings
TODO: Bind to port 80
TODO: Reimplement capture methods
TODO: Implement API route to cleanly shut down server
TODO: Implement microscope function API routes (autofocus etc)
"""
@@ -30,17 +28,11 @@ import logging, sys

logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)

# Create a dummy microscope object, with no hardware attachments
api_microscope = Microscope(None, None)
logging.debug("Created an empty microscope in global.")

# Create flask app
app = Flask(__name__)

# Make errors more API friendly
@app.errorhandler(404)
def not_found(error):
    return make_response(jsonify({'error': 'Not found'}), 404)

# Some useful functions
# TODO: Maybe auto-generate API URI base from module name
# Generate API URI based on version from filename
def uri(suffix, base=None):
    if not base:
        api_ver = os.path.splitext(os.path.basename(__file__))[0]
@@ -49,9 +41,14 @@ def uri(suffix, base=None):
    logging.debug("Created app route: {}".format(uri))
    return uri

# Create a dummy microscope object, with no hardware attachments
api_microscope = Microscope(None, None)
logging.debug("Created an empty microscope in global.")
# Create flask app
app = Flask(__name__)

# Make errors more API friendly
@app.errorhandler(404)
def not_found(error):
    return make_response(jsonify({'error': 'Not found'}), 404)


# After app starts, but before first request, attach hardware to global microscope
@app.before_first_request