From 92a43f575e5b38d76ad1994bb5e8aa4599b45679 Mon Sep 17 00:00:00 2001 From: Cody Baker Date: Wed, 5 Jun 2024 11:41:20 -0400 Subject: [PATCH 1/2] move namespaces around --- src/pyflask/app.py | 2 ++ src/pyflask/namespaces/__init__.py | 1 + src/pyflask/namespaces/neuroconv.py | 2 +- src/pyflask/namespaces/nwb_inspector.py | 43 +++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/pyflask/namespaces/nwb_inspector.py diff --git a/src/pyflask/app.py b/src/pyflask/app.py index 28b0f8a308..f75b6f91cf 100644 --- a/src/pyflask/app.py +++ b/src/pyflask/app.py @@ -34,6 +34,7 @@ neurosift_namespace, startup_namespace, system_namespace, + nwb_inspector_namespace, ) neurosift_file_registry = collections.defaultdict(bool) @@ -65,6 +66,7 @@ api.add_namespace(data_namespace) api.add_namespace(system_namespace) api.add_namespace(dandi_namespace) +api.add_namespace(nwb_inspector_namespace) # api.add_namespace(neurosift_namespace) # TODO: enable later api.init_app(flask_app) diff --git a/src/pyflask/namespaces/__init__.py b/src/pyflask/namespaces/__init__.py index 0f1edb2741..de458f32ab 100644 --- a/src/pyflask/namespaces/__init__.py +++ b/src/pyflask/namespaces/__init__.py @@ -4,3 +4,4 @@ from .neurosift import neurosift_namespace from .startup import startup_namespace from .system import system_namespace +from .nwb_inspector import nwb_inspector_namespace diff --git a/src/pyflask/namespaces/neuroconv.py b/src/pyflask/namespaces/neuroconv.py index 24b16f3077..14a1dcbeb8 100644 --- a/src/pyflask/namespaces/neuroconv.py +++ b/src/pyflask/namespaces/neuroconv.py @@ -171,7 +171,7 @@ def post(self): @neuroconv_namespace.route("/announce/progress") -class InspectNWBFolder(Resource): +class AnnounceProgress(Resource): @neuroconv_namespace.doc(responses={200: "Success", 400: "Bad Request", 500: "Internal server error"}) def post(self): data = neuroconv_namespace.payload diff --git a/src/pyflask/namespaces/nwb_inspector.py b/src/pyflask/namespaces/nwb_inspector.py new file mode 100644 index 0000000000..def84624ed --- /dev/null +++ b/src/pyflask/namespaces/nwb_inspector.py @@ -0,0 +1,43 @@ +"""An API for handling general system information.""" +import os +from typing import Dict, Union + +import flask_restx + +nwb_inspector_namespace = flask_restx.Namespace(name="nwb_inspector", description="Handles interactions with the NWB " + "Inspector.") + + +# TODO: reroute all frontend calls to the new namespace + +@nwb_inspector_namespace.route("/inspect") +class InspectRouter(Resource): + @nwb_inspector_namespace.doc(responses={200: "Success", 400: "Bad Request", 500: "Internal server error"}) + def post(self): + progress_url = f"{request.url_root}neuroconv/announce/progress" + + paths = nwb_inspector_namespace.payload["paths"] + kwargs = {**nwb_inspector_namespace.payload} + del kwargs["paths"] + + if len(paths) == 1: + if os.path.isfile(paths[0]): + return inspect_nwb_file({"nwbfile_path": paths[0], **kwargs}) + else: + return inspect_nwb_folder(url, {"path": paths[0], **kwargs}) + else: + return inspect_multiple_filesystem_objects(progress_url, paths, **kwargs) + +@nwb_inspector_namespace.route("/inspect_file") +class InspectNWBFile(Resource): + @nwb_inspector_namespace.doc(responses={200: "Success", 400: "Bad Request", 500: "Internal server error"}) + def post(self): + return inspect_nwb_file(neuroconv_namespace.payload) + + +@nwb_inspector_namespace.route("/inspect_folder") +class InspectNWBFolder(Resource): + @nwb_inspector_namespace.doc(responses={200: "Success", 400: "Bad Request", 500: "Internal server error"}) + def post(self): + url = f"{request.url_root}neuroconv/announce/progress" + return inspect_nwb_folder(url, neuroconv_namespace.payload) From 587e49263a005cbf6cb3978b8ab5f4a5a5f68b8e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 5 Jun 2024 16:35:05 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/pyflask/app.py | 2 +- src/pyflask/namespaces/__init__.py | 2 +- src/pyflask/namespaces/nwb_inspector.py | 8 ++++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/pyflask/app.py b/src/pyflask/app.py index f75b6f91cf..8a05a58782 100644 --- a/src/pyflask/app.py +++ b/src/pyflask/app.py @@ -32,9 +32,9 @@ data_namespace, neuroconv_namespace, neurosift_namespace, + nwb_inspector_namespace, startup_namespace, system_namespace, - nwb_inspector_namespace, ) neurosift_file_registry = collections.defaultdict(bool) diff --git a/src/pyflask/namespaces/__init__.py b/src/pyflask/namespaces/__init__.py index de458f32ab..fdaa730609 100644 --- a/src/pyflask/namespaces/__init__.py +++ b/src/pyflask/namespaces/__init__.py @@ -2,6 +2,6 @@ from .data import data_namespace from .neuroconv import neuroconv_namespace from .neurosift import neurosift_namespace +from .nwb_inspector import nwb_inspector_namespace from .startup import startup_namespace from .system import system_namespace -from .nwb_inspector import nwb_inspector_namespace diff --git a/src/pyflask/namespaces/nwb_inspector.py b/src/pyflask/namespaces/nwb_inspector.py index def84624ed..a1c5832e75 100644 --- a/src/pyflask/namespaces/nwb_inspector.py +++ b/src/pyflask/namespaces/nwb_inspector.py @@ -1,15 +1,18 @@ """An API for handling general system information.""" + import os from typing import Dict, Union import flask_restx -nwb_inspector_namespace = flask_restx.Namespace(name="nwb_inspector", description="Handles interactions with the NWB " - "Inspector.") +nwb_inspector_namespace = flask_restx.Namespace( + name="nwb_inspector", description="Handles interactions with the NWB " "Inspector." +) # TODO: reroute all frontend calls to the new namespace + @nwb_inspector_namespace.route("/inspect") class InspectRouter(Resource): @nwb_inspector_namespace.doc(responses={200: "Success", 400: "Bad Request", 500: "Internal server error"}) @@ -28,6 +31,7 @@ def post(self): else: return inspect_multiple_filesystem_objects(progress_url, paths, **kwargs) + @nwb_inspector_namespace.route("/inspect_file") class InspectNWBFile(Resource): @nwb_inspector_namespace.doc(responses={200: "Success", 400: "Bad Request", 500: "Internal server error"})