Commit b81cfaf9 authored by Joel Collins's avatar Joel Collins
Browse files

Converted all configs to JSON

parent 94a8774c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@ Microscope RC file
------------------

Microscope configuration is made persistent via a microscope runtime-config (RC) file. By default, this
file exists at ``~/.openflexure/microscope_settings.yaml``, and contains basic parameters to set up the microscope.
file exists at ``~/.openflexure/microscope_settings.json``, and contains basic parameters to set up the microscope.

Additionally, by default, configurations for specific pieces of hardware (i.e. the stage and camera) are located
in separate "auxillary" config files, and are linked together by adding the config file's path to your main
+8 −7
Original line number Diff line number Diff line
@@ -25,17 +25,18 @@ Generally, for adding anything other than very simple functionality, plugins sho

The main restriction is that the plugin package must be importable using an absolute import from within the Python environment being used to load your microscope. 

Loading plugins with microscope_settings.yaml
Loading plugins with microscope_settings.json
---------------------------------------------
Both types of plugin are loaded by specifying the plugin class in your :ref:`MicroscopeRC`. In the case of a single-file plugin, specify the path to the plugin file, followed by the name of your :py:class:`openflexure_microscope.plugins.MicroscopePlugin` child class, separated by a colon. For packaged plugins, specify the absolute module name in place of the path.

For example, the plugins section of your microscope_settings.yaml file may look like:
For example, the plugins section of your microscope_settings.json file may look like:

.. code-block:: yaml
.. code-block:: json

    ...
    plugins:
    - openflexure_microscope.plugins.default:Plugin
    - ~/my_plugins/my_plugin_file.py:MyPluginClass
    - my_openflexure_plugins.microscope.mypluginpackage:MyPluginClass
    "plugins": [
      "openflexure_microscope.plugins.default:Plugin",
      "~/my_plugins/my_plugin_file.py:MyPluginClass",
      "my_openflexure_plugins.microscope.mypluginpackage:MyPluginClass"
    ]
    ...
+6 −2
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ from openflexure_microscope.api.utilities import list_routes
from openflexure_microscope import Microscope

from openflexure_microscope.camera.capture import build_captures_from_exif
from openflexure_microscope.config import USER_CONFIG_DIR
from openflexure_microscope.config import settings_file_path, JSONEncoder
from openflexure_microscope.api.v1 import blueprints

# Import device modules
@@ -38,7 +38,7 @@ from openflexure_microscope.stage.mock import MockStage
# Handle logging
is_gunicorn = "gunicorn" in os.environ.get("SERVER_SOFTWARE", "")

DEFAULT_LOGFILE = os.path.join(USER_CONFIG_DIR, "openflexure_microscope.log")
DEFAULT_LOGFILE = settings_file_path("openflexure_microscope.log")

if (__name__ == "__main__") or (not is_gunicorn):
    # If imported, but not by gunicorn
@@ -109,6 +109,10 @@ def uri(suffix, api_version, base=None):
app = Flask(__name__)
app.url_map.strict_slashes = False

# Use custom JSON encoder
app.json_encoder = JSONEncoder

# Enable CORS everywhere
CORS(app, resources=r"*")

# Make errors more API friendly
+0 −15
Original line number Diff line number Diff line
@@ -9,21 +9,6 @@ def construct_blueprint(microscope_obj):

    blueprint = Blueprint("camera_blueprint", __name__)

    # Metadata routes
    blueprint.add_url_rule(
        "/capture/<capture_id>/metadata/<filename>",
        view_func=capture.MetadataAPI.as_view(
            "metadata_download", microscope=microscope_obj
        ),
    )

    blueprint.add_url_rule(
        "/capture/<capture_id>/metadata",
        view_func=capture.MetadataRedirectAPI.as_view(
            "metadata_download_redirect", microscope=microscope_obj
        ),
    )

    # Tag routes
    blueprint.add_url_rule(
        "/capture/<capture_id>/tags",
+4 −74
Original line number Diff line number Diff line
@@ -236,7 +236,7 @@ class CaptureAPI(MicroscopeView):

    def put(self, capture_id):
        """
        Add arbitrary metadata to the capture (stored in an accompanying capture `.yaml` file)
        Add arbitrary metadata to the capture

        .. :quickref: Capture; Update capture metadata

@@ -351,76 +351,6 @@ class DownloadAPI(MicroscopeView):
        return send_file(img, mimetype="image/jpeg")


class MetadataRedirectAPI(MicroscopeView):
    def get(self, capture_id):
        """
        Return metadatadata for a capture.

        Return capture metadata as a YAML file with the requested filename. 
        I.e., `/(capture_id)/download/bar.yaml` will download the file as 
        `bar.yaml`, regardless of the capture's initially set filename.

        Route automatically redirects to download the capture metadata under it's currently set filename. 
        I.e., `/(capture_id)/download` will 
        redirect to `/(capture_id)/download/(filename)`.

        .. :quickref: Capture; Download capture metadata

        **Example request**:

        .. sourcecode:: http

          GET /camera/capture/d0b2067abbb946f19351e075c5e7cd5b/metadata/2018-11-20_16-04-17.yaml HTTP/1.1
          Accept: text/yaml

        :>header Accept: text/yaml
        :query as_attachment: return the image as an attachment download e.g. ?as_attachment=true

        :>header Content-Type: text/yaml
        :status 200: capture data found
        :status 404: no capture found with that id

        """
        capture_obj = self.microscope.camera.image_from_id(capture_id)

        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,
        )


class MetadataAPI(MicroscopeView):
    def get(self, capture_id, filename):

        capture_obj = self.microscope.camera.image_from_id(capture_id)

        if not capture_obj or not capture_obj.state["available"]:
            return abort(404)  # 404 Not Found

        # 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,
            )

        # Download the metadata using the requested filename
        data = capture_obj.yaml

        return Response(data, mimetype="text/yaml")


class TagsAPI(MicroscopeView):
    def get(self, capture_id):
        """
@@ -433,11 +363,11 @@ class TagsAPI(MicroscopeView):
        .. sourcecode:: http

          GET /camera/capture/d0b2067abbb946f19351e075c5e7cd5b/tags HTTP/1.1
          Accept: text/yaml
          Accept: text/json

        :>header Accept: text/yaml
        :>header Accept: text/json

        :>header Content-Type: text/yaml
        :>header Content-Type: text/json
        :status 200: capture data found
        :status 404: no capture found with that id
        """
Loading