Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve NWB Inspector calls #833

Closed
wants to merge 8 commits into from
2 changes: 2 additions & 0 deletions src/pyflask/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
data_namespace,
neuroconv_namespace,
neurosift_namespace,
nwb_inspector_namespace,
startup_namespace,
system_namespace,
)
Expand Down Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions src/pyflask/namespaces/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +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
2 changes: 1 addition & 1 deletion src/pyflask/namespaces/neuroconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,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
Expand Down
47 changes: 47 additions & 0 deletions src/pyflask/namespaces/nwb_inspector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""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)
Loading