From 259ec4150fa36a24199f0cc4d07e8177422a81c0 Mon Sep 17 00:00:00 2001 From: Joel Collins Date: Mon, 19 Nov 2018 16:33:21 +0000 Subject: [PATCH] Minor restructure --- openflexure_microscope/api/v1.py | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/openflexure_microscope/api/v1.py b/openflexure_microscope/api/v1.py index 447110cf..a3609b7d 100644 --- a/openflexure_microscope/api/v1.py +++ b/openflexure_microscope/api/v1.py @@ -1,8 +1,6 @@ #!/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,6 +28,18 @@ 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.") + +# 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] + base = "/api/{}".format(api_ver) + uri = base + suffix + logging.debug("Created app route: {}".format(uri)) + return uri # Create flask app app = Flask(__name__) @@ -39,19 +49,6 @@ app = Flask(__name__) 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 -def uri(suffix, base=None): - if not base: - api_ver = os.path.splitext(os.path.basename(__file__))[0] - base = "/api/{}".format(api_ver) - uri = base + suffix - 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.") # After app starts, but before first request, attach hardware to global microscope @app.before_first_request