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

Add tool check endpoint #3659

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions cea/interfaces/dashboard/api/tools.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@



from flask import current_app
from flask_restx import Namespace, Resource, fields
from flask_restx import Namespace, Resource, fields, abort

import cea.scripts
from cea.schemas import schemas
from .utils import deconstruct_parameters

api = Namespace('Tools', description='Scripts for CEA')
Expand Down Expand Up @@ -92,6 +90,29 @@ def post(self, tool_name):
return 'Success'


@api.route('/<string:tool_name>/check')
class ToolCheck(Resource):
def get(self, tool_name: str):
config = current_app.cea_config
script = cea.scripts.by_name(tool_name, plugins=config.plugins)
schema_data = schemas(config.plugins)

script_suggestions = set()

for method_name, path in script.missing_input_files(config):
_script_suggestions = schema_data[method_name]['created_by'] if 'created_by' in schema_data[method_name] else None

if _script_suggestions is not None:
script_suggestions.update(_script_suggestions)

if script_suggestions:
scripts = []
for script_suggestion in script_suggestions:
_script = cea.scripts.by_name(script_suggestion, plugins=config.plugins)
scripts.append({"label": _script.label, "name": _script.name})

abort(400, detail={"message": "Missing input files","script_suggestions": list(scripts)})

def parameters_for_script(script_name, config):
"""Return a list consisting of :py:class:`cea.config.Parameter` objects for each parameter of a script"""
parameters = [p for _, p in config.matching_parameters(
Expand Down
Loading