From 465ed647d33f313f45dcf829437e79674c1ca2ce Mon Sep 17 00:00:00 2001 From: Joel Collins Date: Thu, 24 Jan 2019 16:24:14 +0000 Subject: [PATCH] Fixed docstrings --- openflexure_microscope/__init__.py | 4 +- .../api/v1/blueprints/camera/capture.py | 78 +++++++++---------- openflexure_microscope/lock.py | 14 ++-- openflexure_microscope/microscope.py | 2 +- openflexure_microscope/plugins/default/api.py | 2 +- openflexure_microscope/task.py | 16 ++-- 6 files changed, 58 insertions(+), 58 deletions(-) diff --git a/openflexure_microscope/__init__.py b/openflexure_microscope/__init__.py index c23ac0c0..ae62d4e0 100644 --- a/openflexure_microscope/__init__.py +++ b/openflexure_microscope/__init__.py @@ -3,4 +3,6 @@ __version__ = "0.1.0" from .microscope import Microscope from . import config -from . import utilities \ No newline at end of file +from . import utilities +from . import task +from . import lock \ No newline at end of file diff --git a/openflexure_microscope/api/v1/blueprints/camera/capture.py b/openflexure_microscope/api/v1/blueprints/camera/capture.py index 9aadb89a..019ac0b5 100644 --- a/openflexure_microscope/api/v1/blueprints/camera/capture.py +++ b/openflexure_microscope/api/v1/blueprints/camera/capture.py @@ -13,7 +13,7 @@ class ListAPI(MicroscopeView): """ Get list of image captures. - .. :quickref: Capture collection; Get collection of captures + .. :quickref: Captures; Get collection of captures :>header Accept: application/json :query include_unavailable: return json representations of captures that have been completely deleted @@ -45,7 +45,7 @@ class ListAPI(MicroscopeView): """ Delete all captures (not yet implemented) - .. :quickref: Capture collection; Delete all captures + .. :quickref: Captures; Delete all captures """ for image in self.microscope.camera.images: image.delete() @@ -58,7 +58,7 @@ class ListAPI(MicroscopeView): """ Create a new image capture. - .. :quickref: Capture collection; New capture + .. :quickref: Captures; New capture **Example request**: @@ -257,25 +257,6 @@ class CaptureAPI(MicroscopeView): class DownloadRedirectAPI(MicroscopeView): def get(self, capture_id): - """ - Redirect to download the capture under it's currently set filename. - I.e., `/(capture_id)/download` will - redirect to `/(capture_id)/download/(filename)`. - - .. :quickref: Capture; Redirect to download - """ - 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 - - thumbnail = get_bool(request.args.get('thumbnail')) - - return redirect(url_for('.capture_download', capture_id=capture_id, filename=capture_obj.filename, thumbnail=thumbnail), code=307) - - -class DownloadAPI(MicroscopeView): - def get(self, capture_id, filename): """ Return image data for a capture. @@ -283,7 +264,11 @@ class DownloadAPI(MicroscopeView): I.e., `/(capture_id)/download/foo.jpeg` will download the image as `foo.jpeg`, regardless of the capture's initially set filename. - .. :quickref: Capture; Download capture file + Route automatically redirects to download the capture under it's currently set filename. + I.e., `/(capture_id)/download` will + redirect to `/(capture_id)/download/(filename)`. + + .. :quickref: Capture; Download capture image **Example request**: @@ -298,6 +283,7 @@ class DownloadAPI(MicroscopeView): :>header Content-Type: image/jpeg :status 200: capture data found :status 404: no capture found with that id + """ capture_obj = self.microscope.camera.image_from_id(capture_id) @@ -306,6 +292,19 @@ class DownloadAPI(MicroscopeView): thumbnail = get_bool(request.args.get('thumbnail')) + return redirect(url_for('.capture_download', capture_id=capture_id, filename=capture_obj.filename, thumbnail=thumbnail), code=307) + + +class DownloadAPI(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 + + thumbnail = get_bool(request.args.get('thumbnail')) + # 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.filename, thumbnail=thumbnail), code=307) @@ -323,23 +322,6 @@ class DownloadAPI(MicroscopeView): class MetadataRedirectAPI(MicroscopeView): def get(self, capture_id): - """ - Redirect 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; Redirect to metadata - """ - 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): """ Return metadatadata for a capture. @@ -347,6 +329,10 @@ class MetadataAPI(MicroscopeView): 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**: @@ -362,9 +348,21 @@ class MetadataAPI(MicroscopeView): :>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 diff --git a/openflexure_microscope/lock.py b/openflexure_microscope/lock.py index 041f4559..20ee0a74 100644 --- a/openflexure_microscope/lock.py +++ b/openflexure_microscope/lock.py @@ -4,10 +4,10 @@ from openflexure_microscope.exceptions import LockError class StrictLock(object): + """ + Class that behaves like a Python RLock, but with stricter timeout conditions and custom exceptions. + """ def __init__(self, timeout=1): - """ - Class that behaves like a Python RLock, but with stricter timeout conditions and custom exceptions. - """ self._lock = RLock() self.timeout = timeout @@ -29,11 +29,11 @@ class StrictLock(object): class CompositeLock(object): + """ + Class that behaves like a :py:class:`openflexure_microscope.lock.StrictLock`, + but allows multiple locks to be acquired and released. + """ def __init__(self, locks, timeout=1): - """ - Class that behaves like a :py:class:`openflexure_microscope.lock.StrictLock`, - but allows multiple locks to be acquired and released. - """ self.locks = locks self.timeout = timeout diff --git a/openflexure_microscope/microscope.py b/openflexure_microscope/microscope.py index f2a6e144..9502a112 100644 --- a/openflexure_microscope/microscope.py +++ b/openflexure_microscope/microscope.py @@ -38,7 +38,7 @@ class Microscope(object): self._config = config # Create a task orchestrator - self.task = TaskOrchestrator() + self.task = TaskOrchestrator() #: :py:class:`openflexure_microscope.task.TaskOrchestrator`: Threaded task orchestrator # Create plugin mountpoint self.plugin = PluginMount(self) #: :py:class:`openflexure_microscope.plugins.PluginMount`: Mounting point for all microscope plugins diff --git a/openflexure_microscope/plugins/default/api.py b/openflexure_microscope/plugins/default/api.py index c2286e78..4bae0f2f 100644 --- a/openflexure_microscope/plugins/default/api.py +++ b/openflexure_microscope/plugins/default/api.py @@ -13,7 +13,7 @@ class IdentifyAPI(MicroscopeViewPlugin): """ Default plugin to return a plaintext representation of the camera and stage objects. - .. :quickref: Default plugin; Show representation of camera and stage objects. + .. :quickref: Default plugin; Identify hardware """ data = self.microscope.plugin.default.identify() # Call a method from our plugin, using the full route return Response(escape(data)) \ No newline at end of file diff --git a/openflexure_microscope/task.py b/openflexure_microscope/task.py index 32191808..c391aace 100644 --- a/openflexure_microscope/task.py +++ b/openflexure_microscope/task.py @@ -8,11 +8,11 @@ from openflexure_microscope.exceptions import TaskDeniedException from openflexure_microscope.utilities import entry_by_id class TaskOrchestrator: + """ + Class responsible for spawning threaded tasks, and storing their returns. + A microscope should contain exactly one instance of `TaskOrchestrator`. + """ def __init__(self): - """ - Class responsible for spawning threaded tasks, and storing their returns. - A microscope should contain exactly one instance of `TaskOrchestrator`. - """ self.tasks = [] #: list: List of `Task` objects @property @@ -79,11 +79,11 @@ class TaskOrchestrator: class Task: + """ + Class responsible for running a task function in a thread, and handling return or errors. + Tasks should be created by an instance of :py:class:`openflexure_microscope.task.TaskOrchestrator`. + """ def __init__(self, function, *args, **kwargs): - """ - Class responsible for running a task function in a thread, and handling return or errors. - Tasks should be created by an instance of :py:class:`openflexure_microscope.task.TaskOrchestrator`. - """ # The task long-running method self.task = function #: function: Function to be called in the task thread. self.args = args #: Positional arguments to be passed to the task function.